
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>四、数据操作 · 计算机笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="海拉尔的三角">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro-fixed/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-ancre-navigation/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-insert-logo-link-website/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-lightbox/css/lightbox.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-auto-scroll-table/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-katex-pro/katex.min.css">
                
            
                
                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-sectionx/sectionx.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-terminull-light/terminull.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="transaction_withNum.html" />
    
    
    <link rel="prev" href="operatorDB_withNum.html" />
    

    
        <link rel="shortcut icon" href="image/ico.png" type="image/x-icon">
    
    
    
    
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="image/ico.png">
    
    
        
    
    
        
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://github.com/spite-triangle" target="_blank" class="custom-link">Github</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../../cpp/cpp.html">
            
                <a href="../../cpp/cpp.html">
            
                    
                    C/C++
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../../cpp/chapter/foundation_withNum.html">
            
                <a href="../../cpp/chapter/foundation_withNum.html">
            
                    
                    一、基础概念
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../../cpp/chapter/keyword_withNum.html">
            
                <a href="../../cpp/chapter/keyword_withNum.html">
            
                    
                    二、关键字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../../cpp/chapter/point_reference_withNum.html">
            
                <a href="../../cpp/chapter/point_reference_withNum.html">
            
                    
                    三、指针与引用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="../../cpp/chapter/oop_withNum.html">
            
                <a href="../../cpp/chapter/oop_withNum.html">
            
                    
                    四、面向对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="../../cpp/chapter/memory_withNum.html">
            
                <a href="../../cpp/chapter/memory_withNum.html">
            
                    
                    五、内存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6" data-path="../../cpp/chapter/process_withNum.html">
            
                <a href="../../cpp/chapter/process_withNum.html">
            
                    
                    六、进程与线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7" data-path="../../cpp/chapter/locks_withNum.html">
            
                <a href="../../cpp/chapter/locks_withNum.html">
            
                    
                    七、锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.8" data-path="../../cpp/chapter/stl_withNum.html">
            
                <a href="../../cpp/chapter/stl_withNum.html">
            
                    
                    八、STL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.9" data-path="../../cpp/chapter/dataStruction_withNum.html">
            
                <a href="../../cpp/chapter/dataStruction_withNum.html">
            
                    
                    九、数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.10" data-path="../../cpp/chapter/array_list_withNum.html">
            
                <a href="../../cpp/chapter/array_list_withNum.html">
            
                    
                    十、数组链表操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.11" data-path="../../cpp/chapter/find_withNum.html">
            
                <a href="../../cpp/chapter/find_withNum.html">
            
                    
                    十一、目标查找
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.12" data-path="../../cpp/chapter/tree_withNum.html">
            
                <a href="../../cpp/chapter/tree_withNum.html">
            
                    
                    十二、树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.13" data-path="../../cpp/chapter/binaryTree_withNum.html">
            
                <a href="../../cpp/chapter/binaryTree_withNum.html">
            
                    
                    十三、二叉树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.14" data-path="../../cpp/chapter/dynamicProgram_withNum.html">
            
                <a href="../../cpp/chapter/dynamicProgram_withNum.html">
            
                    
                    十四、动态规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.15" data-path="../../cpp/chapter/backtracking_withNum.html">
            
                <a href="../../cpp/chapter/backtracking_withNum.html">
            
                    
                    十五、回溯算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.16" data-path="../../cpp/chapter/monotoneStack_withNum.html">
            
                <a href="../../cpp/chapter/monotoneStack_withNum.html">
            
                    
                    十六、单调栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.17" data-path="../../cpp/chapter/toollib_withNum.html">
            
                <a href="../../cpp/chapter/toollib_withNum.html">
            
                    
                    附录 工具库
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../mysql.html">
            
                <a href="../mysql.html">
            
                    
                    MySQL
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="introduction_withNum.html">
            
                <a href="introduction_withNum.html">
            
                    
                    一、简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="foundation_withNum.html">
            
                <a href="foundation_withNum.html">
            
                    
                    二、控制台操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="operatorDB_withNum.html">
            
                <a href="operatorDB_withNum.html">
            
                    
                    三、数据库、表操作
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="3.1.4" data-path="operatorData_withNum.html">
            
                <a href="operatorData_withNum.html">
            
                    
                    四、数据操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.5" data-path="transaction_withNum.html">
            
                <a href="transaction_withNum.html">
            
                    
                    五、事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.6" data-path="index_withNum.html">
            
                <a href="index_withNum.html">
            
                    
                    六、索引
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.7" data-path="authority_withNum.html">
            
                <a href="authority_withNum.html">
            
                    
                    七、权限管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.8" data-path="backup_withNum.html">
            
                <a href="backup_withNum.html">
            
                    
                    八、备份
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../../linux/linux.html">
            
                <a href="../../linux/linux.html">
            
                    
                    Linux
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../../linux/chapter/foundation_withNum.html">
            
                <a href="../../linux/chapter/foundation_withNum.html">
            
                    
                    一、原理知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../../linux/chapter/command_withNum.html">
            
                <a href="../../linux/chapter/command_withNum.html">
            
                    
                    二、指令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../../tcp_udp/tcp_upd.html">
            
                <a href="../../tcp_udp/tcp_upd.html">
            
                    
                    网络
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.1" data-path="../../tcp_udp/chapter/foundation_withNum.html">
            
                <a href="../../tcp_udp/chapter/foundation_withNum.html">
            
                    
                    一、网络通讯基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.2" data-path="../../tcp_udp/chapter/tcp_udp_withNum.html">
            
                <a href="../../tcp_udp/chapter/tcp_udp_withNum.html">
            
                    
                    二、tcp/udp
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >四、数据操作</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-anchor"></i><ul><li><span class="title-icon "></span><a href="#&#x6570;&#x636E;&#x64CD;&#x4F5C;"><b></b>&#x6570;&#x636E;&#x64CD;&#x4F5C;</a></li><li><span class="title-icon "></span><a href="#1-&#x5916;&#x952E;"><b></b>1. &#x5916;&#x952E;</a></li><ul><li><span class="title-icon "></span><a href="#11-&#x6982;&#x5FF5;"><b></b>1.1. &#x6982;&#x5FF5;</a></li><li><span class="title-icon "></span><a href="#12-&#x5916;&#x952E;&#x7684;&#x521B;&#x5EFA;"><b></b>1.2. &#x5916;&#x952E;&#x7684;&#x521B;&#x5EFA;</a></li><ul><li><span class="title-icon "></span><a href="#121-&#x751F;&#x6210;&#x8868;&#x65F6;&#x521B;&#x5EFA;"><b></b>1.2.1. &#x751F;&#x6210;&#x8868;&#x65F6;&#x521B;&#x5EFA;</a></li><li><span class="title-icon "></span><a href="#122-&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7684;&#x8868;"><b></b>1.2.2. &#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7684;&#x8868;</a></li></ul><li><span class="title-icon "></span><a href="#13-&#x5916;&#x952E;&#x8868;&#x5220;&#x9664;&#x987A;&#x5E8F;"><b></b>1.3. &#x5916;&#x952E;&#x8868;&#x5220;&#x9664;&#x987A;&#x5E8F;</a></li><li><span class="title-icon "></span><a href="#14-&#x91CD;&#x70B9;"><b></b>1.4. &#x91CD;&#x70B9;</a></li></ul><li><span class="title-icon "></span><a href="#2-dml&#x8BED;&#x8A00;&#x91CD;&#x70B9;"><b></b>2. DML&#x8BED;&#x8A00;(&#x91CD;&#x70B9;)</a></li><ul><li><span class="title-icon "></span><a href="#21-&#x6982;&#x5FF5;"><b></b>2.1. &#x6982;&#x5FF5;</a></li><li><span class="title-icon "></span><a href="#22-&#x589E;-insert"><b></b>2.2. &#x589E; insert</a></li><li><span class="title-icon "></span><a href="#23-&#x6539;-update"><b></b>2.3. &#x6539; update</a></li><li><span class="title-icon "></span><a href="#24-&#x5220;"><b></b>2.4. &#x5220;</a></li><ul><li><span class="title-icon "></span><a href="#241-delete"><b></b>2.4.1. delete</a></li><li><span class="title-icon "></span><a href="#242-truncate"><b></b>2.4.2. truncate</a></li><li><span class="title-icon "></span><a href="#243-&#x5BF9;&#x6BD4;"><b></b>2.4.3. &#x5BF9;&#x6BD4;</a></li></ul></ul><li><span class="title-icon "></span><a href="#3-dql&#x8BED;&#x8A00;&#x91CD;&#x70B9;"><b></b>3. DQL&#x8BED;&#x8A00;(&#x91CD;&#x70B9;)</a></li><ul><li><span class="title-icon "></span><a href="#31-&#x6982;&#x5FF5;"><b></b>3.1. &#x6982;&#x5FF5;</a></li><li><span class="title-icon "></span><a href="#32-&#x57FA;&#x7840;&#x7528;&#x6CD5;"><b></b>3.2. &#x57FA;&#x7840;&#x7528;&#x6CD5;</a></li><ul><li><span class="title-icon "></span><a href="#321-&#x67E5;&#x8BE2;&#x5B57;&#x6BB5;"><b></b>3.2.1. &#x67E5;&#x8BE2;&#x5B57;&#x6BB5;</a></li><li><span class="title-icon "></span><a href="#322-as&#x522B;&#x540D;"><b></b>3.2.2. as&#x522B;&#x540D;</a></li><li><span class="title-icon "></span><a href="#323-&#x6570;&#x636E;&#x6DFB;&#x52A0;&#x5B57;&#x7B26;&#x4E32;"><b></b>3.2.3. &#x6570;&#x636E;&#x6DFB;&#x52A0;&#x5B57;&#x7B26;&#x4E32;</a></li><li><span class="title-icon "></span><a href="#324-&#x67E5;&#x51FD;&#x6570;"><b></b>3.2.4. &#x67E5;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#325-&#x6570;&#x5B66;&#x8BA1;&#x7B97;"><b></b>3.2.5. &#x6570;&#x5B66;&#x8BA1;&#x7B97;</a></li><li><span class="title-icon "></span><a href="#326-&#x67E5;&#x7CFB;&#x7EDF;&#x53D8;&#x91CF;"><b></b>3.2.6. &#x67E5;&#x7CFB;&#x7EDF;&#x53D8;&#x91CF;</a></li><li><span class="title-icon "></span><a href="#327-&#x53BB;&#x91CD;-distinct"><b></b>3.2.7. &#x53BB;&#x91CD; distinct</a></li><li><span class="title-icon "></span><a href="#328-&#x9009;&#x62E9;&#x6027;&#x67E5;&#x8BE2;where"><b></b>3.2.8. &#x9009;&#x62E9;&#x6027;&#x67E5;&#x8BE2;where</a></li></ul><li><span class="title-icon "></span><a href="#33-&#x8868;&#x8FBE;&#x5F0F;"><b></b>3.3. &#x8868;&#x8FBE;&#x5F0F;</a></li></ul><li><span class="title-icon "></span><a href="#4-&#x6761;&#x4EF6;&#x8FC7;&#x6EE4;where"><b></b>4. &#x6761;&#x4EF6;&#x8FC7;&#x6EE4;where</a></li><ul><li><span class="title-icon "></span><a href="#41-&#x4E00;&#x822C;&#x6761;&#x4EF6;"><b></b>4.1. &#x4E00;&#x822C;&#x6761;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#42-&#x6A21;&#x7CCA;&#x6761;&#x4EF6;"><b></b>4.2. &#x6A21;&#x7CCA;&#x6761;&#x4EF6;</a></li></ul><li><span class="title-icon "></span><a href="#5-&#x8054;&#x8868;&#x67E5;&#x8BE2;"><b></b>5. &#x8054;&#x8868;&#x67E5;&#x8BE2;</a></li><ul><li><span class="title-icon "></span><a href="#51-&#x6982;&#x5FF5;"><b></b>5.1. &#x6982;&#x5FF5;</a></li><li><span class="title-icon "></span><a href="#52-&#x8FDE;&#x63A5;&#x65B9;&#x5F0F;"><b></b>5.2. &#x8FDE;&#x63A5;&#x65B9;&#x5F0F;</a></li></ul><li><span class="title-icon "></span><a href="#6-&#x81EA;&#x8FDE;&#x67E5;&#x8BE2;&#xFF08;&#x4E86;&#x89E3;&#xFF09;"><b></b>6. &#x81EA;&#x8FDE;&#x67E5;&#x8BE2;&#xFF08;&#x4E86;&#x89E3;&#xFF09;</a></li><li><span class="title-icon "></span><a href="#7-&#x5206;&#x7EC4;-group-by"><b></b>7. &#x5206;&#x7EC4; group by</a></li><li><span class="title-icon "></span><a href="#8-&#x7EC4;&#x8FC7;&#x6EE4;-having"><b></b>8. &#x7EC4;&#x8FC7;&#x6EE4; having</a></li><li><span class="title-icon "></span><a href="#9-&#x6392;&#x5E8F;order-by"><b></b>9. &#x6392;&#x5E8F;order by</a></li><li><span class="title-icon "></span><a href="#10-&#x5206;&#x9875;limit"><b></b>10. &#x5206;&#x9875;limit</a></li><li><span class="title-icon "></span><a href="#11-&#x5D4C;&#x5957;&#x67E5;&#x8BE2;"><b></b>11. &#x5D4C;&#x5957;&#x67E5;&#x8BE2;</a></li><li><span class="title-icon "></span><a href="#12-&#x51FD;&#x6570;"><b></b>12. &#x51FD;&#x6570;</a></li><ul><li><span class="title-icon "></span><a href="#121-&#x5E38;&#x7528;&#x51FD;&#x6570;"><b></b>12.1. &#x5E38;&#x7528;&#x51FD;&#x6570;</a></li><ul><li><span class="title-icon "></span><a href="#1211-&#x6570;&#x5B66;"><b></b>12.1.1. &#x6570;&#x5B66;</a></li><li><span class="title-icon "></span><a href="#1212-&#x5B57;&#x7B26;&#x4E32;"><b></b>12.1.2. &#x5B57;&#x7B26;&#x4E32;</a></li><li><span class="title-icon "></span><a href="#1213-&#x65F6;&#x95F4;"><b></b>12.1.3. &#x65F6;&#x95F4;</a></li><li><span class="title-icon "></span><a href="#1214-&#x7CFB;&#x7EDF;"><b></b>12.1.4. &#x7CFB;&#x7EDF;</a></li></ul><li><span class="title-icon "></span><a href="#122-&#x805A;&#x5408;&#x51FD;&#x6570;&#xFF08;&#x91CD;&#x8981;&#xFF09;"><b></b>12.2. &#x805A;&#x5408;&#x51FD;&#x6570;&#xFF08;&#x91CD;&#x8981;&#xFF09;</a></li><ul><li><span class="title-icon "></span><a href="#1221-count"><b></b>12.2.1. count()</a></li></ul><li><span class="title-icon "></span><a href="#123-md5&#x52A0;&#x5BC6;"><b></b>12.3. MD5()&#x52A0;&#x5BC6;</a></li></ul><li><span class="title-icon "></span><a href="#13-select&#x603B;&#x7ED3;"><b></b>13. select&#x603B;&#x7ED3;</a></li></ul></div><a href="#&#x6570;&#x636E;&#x64CD;&#x4F5C;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 style="font-size:60px;text-align:center;" id="&#x6570;&#x636E;&#x64CD;&#x4F5C;"><a name="&#x6570;&#x636E;&#x64CD;&#x4F5C;" class="anchor-navigation-ex-anchor" href="#&#x6570;&#x636E;&#x64CD;&#x4F5C;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6570;&#x636E;&#x64CD;&#x4F5C;</h1>

<h1 id="1-&#x5916;&#x952E;"><a name="1-&#x5916;&#x952E;" class="anchor-navigation-ex-anchor" href="#1-&#x5916;&#x952E;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x5916;&#x952E;</h1>
<h2 id="11-&#x6982;&#x5FF5;"><a name="11-&#x6982;&#x5FF5;" class="anchor-navigation-ex-anchor" href="#11-&#x6982;&#x5FF5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. &#x6982;&#x5FF5;</h2>
<p><span style="color:blue;font-weight:bold"> &#x5C06;&#x4E24;&#x4E2A;&#x8868;&#x7684;&#x5B57;&#x6BB5;&#x5173;&#x8054;&#x8D77;&#x6765;&#xFF0C;&#x5F62;&#x6210;&#x8868;&#x95F4;&#x5173;&#x7CFB;&#x3002; </span></p>
<h2 id="12-&#x5916;&#x952E;&#x7684;&#x521B;&#x5EFA;"><a name="12-&#x5916;&#x952E;&#x7684;&#x521B;&#x5EFA;" class="anchor-navigation-ex-anchor" href="#12-&#x5916;&#x952E;&#x7684;&#x521B;&#x5EFA;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. &#x5916;&#x952E;&#x7684;&#x521B;&#x5EFA;</h2>
<blockquote>
<p>[!note]</p>
<ol>
<li>&#x8BBE;&#x7F6E;&#x4E3A;&#x5916;&#x952E;&#x7684;&#x5B57;&#x6BB5;&#x4E0D;&#x80FD;&#x4E3A;&#x4E3B;&#x952E;</li>
<li>&#x6539;&#x952E;&#x6240;&#x53C2;&#x8003;&#x7684;&#x5B57;&#x6BB5;&#x5FC5;&#x987B;&#x4E3A;&#x4E3B;&#x952E;</li>
<li>&#x4E24;&#x4E2A;&#x5B57;&#x6BB5;&#x5FC5;&#x987B;&#x6709;&#x76F8;&#x540C;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x548C;&#x7EA6;&#x675F;</li>
</ol>
</blockquote>
<h3 id="121-&#x751F;&#x6210;&#x8868;&#x65F6;&#x521B;&#x5EFA;"><a name="121-&#x751F;&#x6210;&#x8868;&#x65F6;&#x521B;&#x5EFA;" class="anchor-navigation-ex-anchor" href="#121-&#x751F;&#x6210;&#x8868;&#x65F6;&#x521B;&#x5EFA;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.1. &#x751F;&#x6210;&#x8868;&#x65F6;&#x521B;&#x5EFA;</h3>
<ol>
<li>&#x5B9A;&#x4E49;&#x5916;&#x952E;</li>
<li>&#x6DFB;&#x52A0;&#x7EA6;&#x675F;</li>
</ol>
<pre class="language-"><code class="lang-sql"><span class="token keyword">create</span> <span class="token keyword">table</span> <span class="token keyword">if</span> <span class="token operator">not</span> <span class="token keyword">exists</span> <span class="token punctuation">`</span>grade<span class="token punctuation">`</span><span class="token punctuation">(</span>
    <span class="token punctuation">`</span>gradeId<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token operator">not</span> <span class="token boolean">null</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x73ED;&#x7EA7;id&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token operator">not</span> <span class="token boolean">null</span> <span class="token keyword">DEFAULT</span> <span class="token string">&apos;&#x4E00;&#x73ED;&apos;</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x73ED;&#x7EA7;&#x540D;&apos;</span><span class="token punctuation">,</span>
    <span class="token keyword">primary</span> <span class="token keyword">key</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>gradeId<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token keyword">engine</span><span class="token operator">=</span><span class="token keyword">INNODB</span> <span class="token keyword">charset</span><span class="token operator">=</span>utf8<span class="token punctuation">;</span>

<span class="token keyword">create</span> <span class="token keyword">table</span> <span class="token keyword">if</span> <span class="token operator">not</span> <span class="token keyword">exists</span> <span class="token punctuation">`</span>student<span class="token punctuation">`</span><span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">not</span> <span class="token boolean">null</span> <span class="token keyword">auto_increment</span> <span class="token keyword">comment</span> <span class="token string">&apos;&#x4E3B;&#x952E;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token operator">not</span> <span class="token boolean">null</span> <span class="token keyword">default</span> <span class="token string">&apos;&#x674E;&#x534E;&apos;</span> <span class="token keyword">comment</span> <span class="token string">&apos;&#x540D;&#x5B57;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>gradeId<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token operator">not</span> <span class="token boolean">null</span> <span class="token keyword">comment</span> <span class="token string">&apos;&#x73ED;&#x7EA7;&apos;</span><span class="token punctuation">,</span>
    <span class="token keyword">primary</span> <span class="token keyword">key</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>

    <span class="token comment">-- &#x5B9A;&#x4E49;&#x5916;&#x952E;</span>
    <span class="token keyword">key</span> <span class="token punctuation">`</span>FK_grade<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>gradeId<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token comment">-- &#x6DFB;&#x52A0;&#x7EA6;&#x675F;</span>
    <span class="token keyword">constraint</span> <span class="token punctuation">`</span>FK_grade<span class="token punctuation">`</span> <span class="token keyword">FOREIGN</span> <span class="token keyword">key</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>gradeId<span class="token punctuation">`</span><span class="token punctuation">)</span> <span class="token keyword">references</span>  <span class="token punctuation">`</span>grade<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>gradeId<span class="token punctuation">`</span><span class="token punctuation">)</span>

<span class="token punctuation">)</span><span class="token keyword">engine</span><span class="token operator">=</span><span class="token keyword">INNODB</span> <span class="token keyword">charset</span><span class="token operator">=</span>utf8<span class="token punctuation">;</span>
</code></pre>
<h3 id="122-&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7684;&#x8868;"><a name="122-&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7684;&#x8868;" class="anchor-navigation-ex-anchor" href="#122-&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7684;&#x8868;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2.2. &#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x7684;&#x8868;</h3>
<pre class="language-"><code class="lang-sql"><span class="token keyword">alter</span> <span class="token keyword">table</span> <span class="token punctuation">`</span>student<span class="token punctuation">`</span> <span class="token keyword">add</span> <span class="token keyword">constraint</span> <span class="token punctuation">`</span>FK_gradeId<span class="token punctuation">`</span> <span class="token keyword">FOREIGN</span> <span class="token keyword">key</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>gradeId<span class="token punctuation">`</span><span class="token punctuation">)</span> <span class="token keyword">REFERENCES</span> <span class="token punctuation">`</span>grade<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>gradeId<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<h2 id="13-&#x5916;&#x952E;&#x8868;&#x5220;&#x9664;&#x987A;&#x5E8F;"><a name="13-&#x5916;&#x952E;&#x8868;&#x5220;&#x9664;&#x987A;&#x5E8F;" class="anchor-navigation-ex-anchor" href="#13-&#x5916;&#x952E;&#x8868;&#x5220;&#x9664;&#x987A;&#x5E8F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. &#x5916;&#x952E;&#x8868;&#x5220;&#x9664;&#x987A;&#x5E8F;</h2>
<ol>
<li>&#x5148;&#x5220;&#x9664;&#x300C;&#x5F15;&#x7528;&#x7684;&#x8868;&#xFF08;&#x4ECE;&#x8868;&#xFF09;&#x300D;</li>
<li>&#x518D;&#x5220;&#x9664;&#x300C;&#x88AB;&#x5F15;&#x7528;&#x7684;&#x8868;&#xFF08;&#x4E3B;&#x8868;&#xFF09;&#x300D;</li>
</ol>
<h2 id="14-&#x91CD;&#x70B9;"><a name="14-&#x91CD;&#x70B9;" class="anchor-navigation-ex-anchor" href="#14-&#x91CD;&#x70B9;"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. &#x91CD;&#x70B9;</h2>
<blockquote>
<p>[!note|style:flat]
<span style="color:red;font-weight:bold"> &#x4E0D;&#x63A8;&#x8350;&#x4F7F;&#x7528;&#x5916;&#x952E;&#x5728;&#x6570;&#x636E;&#x5E93;&#x5C42;&#x9762;&#x5173;&#x8054;&#x4E24;&#x5F20;&#x8868;&#xFF0C;&#x800C;&#x662F;&#x5229;&#x7528;&#x4EE3;&#x7801;&#x5728;&#x5E94;&#x7528;&#x5C42;&#x5BF9;&#x8868;&#x8FDB;&#x884C;&#x5173;&#x8054;&#x3002; </span></p>
</blockquote>
<h1 id="2-dml&#x8BED;&#x8A00;&#x91CD;&#x70B9;"><a name="2-dml&#x8BED;&#x8A00;&#x91CD;&#x70B9;" class="anchor-navigation-ex-anchor" href="#2-dml&#x8BED;&#x8A00;&#x91CD;&#x70B9;"><i class="fa fa-link" aria-hidden="true"></i></a>2. DML&#x8BED;&#x8A00;(&#x91CD;&#x70B9;)</h1>
<h2 id="21-&#x6982;&#x5FF5;"><a name="21-&#x6982;&#x5FF5;" class="anchor-navigation-ex-anchor" href="#21-&#x6982;&#x5FF5;"><i class="fa fa-link" aria-hidden="true"></i></a>2.1. &#x6982;&#x5FF5;</h2>
<p><code>DML</code>: <strong>&#x6570;&#x636E;&#x64CD;&#x4F5C;&#x8BED;&#x8A00;&#xFF08;Data Manipulation Language&#xFF09;</strong> &#x662F;&#x7528;&#x4E8E;&#x6570;&#x636E;&#x5E93;&#x64CD;&#x4F5C;&#xFF0C;&#x5BF9;&#x6570;&#x636E;&#x5E93;&#x5176;&#x4E2D;&#x7684;&#x5BF9;&#x8C61;&#x548C;&#x6570;&#x636E;&#x8FD0;&#x884C;&#x8BBF;&#x95EE;&#x5DE5;&#x4F5C;&#x7684;&#x7F16;&#x7A0B;&#x8BED;&#x53E5;&#x3002;</p>
<ul>
<li><code>insert</code>&#xFF1A;<strong>&#x589E;</strong></li>
<li><code>delete</code>&#xFF1A;<strong>&#x5220;</strong></li>
<li><code>update</code>&#xFF1A;<strong>&#x6539;</strong></li>
</ul>
<blockquote>
<p>[!note|style:flat]
<strong>&#x8BBE;&#x7F6E;&#x4E86;<code>not null</code>&#x7684;&#x5B57;&#x6BB5;&#xFF0C;&#x5728;<code>insert,update</code>&#x65F6;&#xFF0C;&#x4E0D;&#x80FD;&#x8D4B;&#x503C;&#x4E3A;<code>null</code>&#x3002;</strong></p>
</blockquote>
<h2 id="22-&#x589E;-insert"><a name="22-&#x589E;-insert" class="anchor-navigation-ex-anchor" href="#22-&#x589E;-insert"><i class="fa fa-link" aria-hidden="true"></i></a>2.2. &#x589E; <code>insert</code></h2>
<pre class="language-"><code class="lang-sql"><span class="token comment">-- &#x5BF9;&#x5E94;&#x5B57;&#x6BB5;&#x63D2;&#x5165;&#x4E00;&#x884C;&#x6570;&#x636E;</span>
<span class="token keyword">insert</span> <span class="token keyword">into</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">1</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">2</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token keyword">values</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>&#x503C;<span class="token number">1</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x503C;<span class="token number">2</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x503C;<span class="token number">3</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">-- &#x4E3B;&#x952E;&#x81EA;&#x589E;&#x53EF;&#x4EE5;&#x4E0D;&#x7528;&#x7BA1;&#xFF0C;&#x4E0D;&#x5199;&#x5B57;&#x6BB5;&#xFF0C;&#x503C;&#x5C31;&#x9ED8;&#x8BA4;&#x4E0E;&#x8868;&#x7684;&#x5B57;&#x6BB5;&#x987A;&#x5E8F;&#x4E00;&#x4E00;&#x5BF9;&#x5E94;</span>
<span class="token keyword">insert</span> <span class="token keyword">into</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token keyword">values</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>&#x503C;<span class="token number">1</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x503C;<span class="token number">2</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x503C;<span class="token number">3</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">-- &#x5BF9;&#x5E94;&#x5B57;&#x6BB5;&#xFF0C;&#x63D2;&#x5165;&#x591A;&#x884C;&#x6570;&#x636E;</span>
<span class="token keyword">insert</span> <span class="token keyword">into</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">1</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">2</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token keyword">values</span>
<span class="token punctuation">(</span><span class="token punctuation">`</span>&#x503C;<span class="token number">1</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x503C;<span class="token number">2</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x503C;<span class="token number">3</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">(</span><span class="token punctuation">`</span>&#x503C;<span class="token number">1</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x503C;<span class="token number">2</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x503C;<span class="token number">3</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">(</span><span class="token punctuation">`</span>&#x503C;<span class="token number">1</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x503C;<span class="token number">2</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x503C;<span class="token number">3</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<ul>
<li><strong>auto_increment</strong>: &#x5E26;&#x6709;&#x81EA;&#x589E;&#x5C5E;&#x6027;&#x7684;&#x503C;&#xFF0C;&#x53EF;&#x4EE5;&#x4E0D;&#x7528;&#x63D2;&#x5165;&#x503C;&#x3002;</li>
</ul>
<sec data-title="&#x6848;&#x4F8B;&#x4EE3;&#x7801;" data-id="insert_example" data-show="true" data-collapse="true"><div class="panel panel-default"><div class="panel-heading"><b>&#x6848;&#x4F8B;&#x4EE3;&#x7801;<a class="pull-right section atTitle btn btn-default" target="insert_example"><span class="fa fa-angle-up"></span></a></b></div><div class="panel-collapse in" id="insert_example"><div class="panel-body">
<pre class="language-"><code class="lang-sql"><span class="token keyword">insert</span> <span class="token keyword">into</span> <span class="token punctuation">`</span>student<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>name<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>age<span class="token punctuation">`</span><span class="token punctuation">)</span> <span class="token keyword">values</span> 
<span class="token punctuation">(</span><span class="token string">&apos;&#x5C0F;&#x660E;&apos;</span><span class="token punctuation">,</span><span class="token string">&apos;20&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">(</span><span class="token string">&apos;&#x5C0F;&#x7EA2;&apos;</span><span class="token punctuation">,</span><span class="token string">&apos;18&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">(</span><span class="token string">&apos;&#x9A6C;&#x91CC;&#x5965;&apos;</span><span class="token punctuation">,</span><span class="token string">&apos;30&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">(</span><span class="token string">&apos;&#x8DEF;&#x6613;&#x5409;&apos;</span><span class="token punctuation">,</span><span class="token string">&apos;29&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
</div></div></div></sec>
<h2 id="23-&#x6539;-update"><a name="23-&#x6539;-update" class="anchor-navigation-ex-anchor" href="#23-&#x6539;-update"><i class="fa fa-link" aria-hidden="true"></i></a>2.3. &#x6539; <code>update</code></h2>
<pre class="language-"><code class="lang-sql"><span class="token comment">-- &#x4FEE;&#x6539;&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;&#x7684;&#x5185;&#x5BB9;</span>
<span class="token keyword">update</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token keyword">set</span> <span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">1</span><span class="token punctuation">`</span><span class="token operator">=</span> value1<span class="token punctuation">,</span><span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">2</span><span class="token punctuation">`</span><span class="token operator">=</span> value2<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token keyword">where</span> &#x6761;&#x4EF6;<span class="token punctuation">;</span>

<span class="token comment">-- &#x4FEE;&#x6539;&#x6574;&#x4E2A;&#x5B57;&#x6BB5;&#x7684;&#x5168;&#x90E8;&#x503C;</span>
<span class="token keyword">update</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token keyword">set</span> <span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token punctuation">`</span><span class="token operator">=</span><span class="token keyword">value</span><span class="token punctuation">;</span>
</code></pre>
<ul>
<li><code>value</code>: &#x53EF;&#x4EE5;&#x662F;&#x5177;&#x4F53;&#x7684;&#x503C;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x53D8;&#x91CF;&#x3002;</li>
</ul>
<h2 id="24-&#x5220;"><a name="24-&#x5220;" class="anchor-navigation-ex-anchor" href="#24-&#x5220;"><i class="fa fa-link" aria-hidden="true"></i></a>2.4. &#x5220;</h2>
<h3 id="241-delete"><a name="241-delete" class="anchor-navigation-ex-anchor" href="#241-delete"><i class="fa fa-link" aria-hidden="true"></i></a>2.4.1. <code>delete</code></h3>
<ul>
<li><strong>&#x5BF9;&#x6570;&#x636E;&#x662F;&#x4E00;&#x884C;&#xFF0C;&#x4E00;&#x884C;&#x7684;&#x5220;&#x9664;&#x3002;</strong></li>
</ul>
<pre class="language-"><code class="lang-sql"><span class="token keyword">delete</span> <span class="token keyword">from</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token keyword">where</span> &#x6761;&#x4EF6;<span class="token punctuation">;</span>
<span class="token comment">-- &#x6E05;&#x7A7A;&#x8868;&#xFF0C;&#x4E0D;&#x5EFA;&#x8BAE;&#x7528;</span>
<span class="token keyword">delete</span> <span class="token keyword">from</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span><span class="token punctuation">;</span>
</code></pre>
<h3 id="242-truncate"><a name="242-truncate" class="anchor-navigation-ex-anchor" href="#242-truncate"><i class="fa fa-link" aria-hidden="true"></i></a>2.4.2. <code>truncate</code></h3>
<ul>
<li>&#x6E05;&#x7A7A;&#x8868;&#x4E2D;&#x6240;&#x6709;&#x6570;&#x636E;&#x3002;</li>
</ul>
<pre class="language-"><code class="lang-sql"><span class="token keyword">truncate</span> <span class="token keyword">table</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span><span class="token punctuation">;</span>
</code></pre>
<h3 id="243-&#x5BF9;&#x6BD4;"><a name="243-&#x5BF9;&#x6BD4;" class="anchor-navigation-ex-anchor" href="#243-&#x5BF9;&#x6BD4;"><i class="fa fa-link" aria-hidden="true"></i></a>2.4.3. &#x5BF9;&#x6BD4;</h3>
<ul>
<li>&#x76F8;&#x540C;&#xFF1A;&#x90FD;&#x80FD;&#x6E05;&#x7A7A;&#x6570;&#x636E;&#xFF0C;&#x4E0D;&#x4F1A;&#x4FEE;&#x6539;&#x8868;&#x7ED3;&#x6784;&#xFF08;<code>alter table</code>&#x624D;&#x80FD;&#x4FEE;&#x80FD;&#x8868;&#x7ED3;&#x6784;&#xFF09;&#x3002;</li>
<li><code>truncate</code>&#x4E0D;&#x540C;&#xFF1A;<ul>
<li><code>auto_increment</code>&#x53EF;&#x4EE5;&#x5F52;<code>0</code></li>
<li>&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x4E8B;&#x52A1;&#x3002;</li>
</ul>
</li>
<li><code>delete</code>&#x4E0D;&#x540C;&#xFF1A;<ul>
<li><code>INNODB</code>&#xFF1A;&#x91CD;&#x542F;&#x6570;&#x636E;&#x5E93;&#x540E;&#xFF0C;<code>auto_increment</code>&#x4F1A;&#x5F52;<code>0</code>&#xFF08;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#xFF09;</li>
<li><code>MYISAM</code>&#xFF1A;&#x91CD;&#x542F;&#x540E;&#x6570;&#x636E;&#x5E93;&#x540E;&#xFF0C;<code>auto_increment</code>&#x4E0D;&#x4F1A;&#x5F52;<code>0</code>&#xFF08;&#x5728;&#x786C;&#x76D8;&#x6587;&#x4EF6;&#x4E2D;&#xFF09;</li>
</ul>
</li>
</ul>
<h1 id="3-dql&#x8BED;&#x8A00;&#x91CD;&#x70B9;"><a name="3-dql&#x8BED;&#x8A00;&#x91CD;&#x70B9;" class="anchor-navigation-ex-anchor" href="#3-dql&#x8BED;&#x8A00;&#x91CD;&#x70B9;"><i class="fa fa-link" aria-hidden="true"></i></a>3. DQL&#x8BED;&#x8A00;(&#x91CD;&#x70B9;)</h1>
<sec data-title="&#x6848;&#x4F8B;&#x4EE3;&#x7801;" data-id="dql_example" data-show="true" data-collapse="true"><div class="panel panel-default"><div class="panel-heading"><b>&#x6848;&#x4F8B;&#x4EE3;&#x7801;<a class="pull-right section atTitle btn btn-default" target="dql_example"><span class="fa fa-angle-up"></span></a></b></div><div class="panel-collapse in" id="dql_example"><div class="panel-body">
<pre class="language-"><code class="lang-sql"><span class="token comment">/*
SQLyog Ultimate v13.1.1 (64 bit)
MySQL - 5.7.33 : Database - school
*********************************************************************
*/</span>

<span class="token comment">/*!40101 SET NAMES utf8 */</span><span class="token punctuation">;</span>

<span class="token comment">/*!40101 SET SQL_MODE = &apos;&apos;*/</span><span class="token punctuation">;</span>

<span class="token comment">/*!40014 SET @OLD_UNIQUE_CHECKS = @@UNIQUE_CHECKS, UNIQUE_CHECKS = 0 */</span><span class="token punctuation">;</span>
<span class="token comment">/*!40014 SET @OLD_FOREIGN_KEY_CHECKS = @@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS = 0 */</span><span class="token punctuation">;</span>
<span class="token comment">/*!40101 SET @OLD_SQL_MODE = @@SQL_MODE, SQL_MODE = &apos;NO_AUTO_VALUE_ON_ZERO&apos; */</span><span class="token punctuation">;</span>
<span class="token comment">/*!40111 SET @OLD_SQL_NOTES = @@SQL_NOTES, SQL_NOTES = 0 */</span><span class="token punctuation">;</span>
<span class="token keyword">CREATE</span> <span class="token keyword">DATABASE</span> <span class="token comment">/*!32312 IF NOT EXISTS */</span><span class="token punctuation">`</span>school<span class="token punctuation">`</span> <span class="token comment">/*!40100 DEFAULT CHARACTER SET utf8 */</span><span class="token punctuation">;</span>

<span class="token keyword">USE</span> <span class="token punctuation">`</span>school<span class="token punctuation">`</span><span class="token punctuation">;</span>

<span class="token comment">/*Table structure for table `grade` */</span>

<span class="token keyword">DROP</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>grade<span class="token punctuation">`</span><span class="token punctuation">;</span>

<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>grade<span class="token punctuation">`</span>
<span class="token punctuation">(</span>
    <span class="token punctuation">`</span>GradeID<span class="token punctuation">`</span>   <span class="token keyword">INT</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span>     <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x5E74;&#x7EA7;&#x7F16;&#x53F7;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>GradeName<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x5E74;&#x7EA7;&#x540D;&#x79F0;&apos;</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>GradeID<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span>
  <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span> <span class="token operator">=</span> utf8<span class="token punctuation">;</span>

<span class="token comment">/*Data for the table `grade` */</span>

<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token punctuation">`</span>grade<span class="token punctuation">`</span><span class="token punctuation">(</span><span class="token punctuation">`</span>GradeID<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>GradeName<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x5927;&#x4E00;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x5927;&#x4E8C;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x5927;&#x4E09;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x5927;&#x56DB;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x9884;&#x79D1;&#x73ED;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">/*Table structure for table `result` */</span>

<span class="token keyword">DROP</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>result<span class="token punctuation">`</span><span class="token punctuation">;</span>

<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>result<span class="token punctuation">`</span>
<span class="token punctuation">(</span>
    <span class="token punctuation">`</span>StudentNo<span class="token punctuation">`</span>     <span class="token keyword">INT</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span>   <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x5B66;&#x53F7;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>SubjectNo<span class="token punctuation">`</span>     <span class="token keyword">INT</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span>   <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x8BFE;&#x7A0B;&#x7F16;&#x53F7;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>ExamDate<span class="token punctuation">`</span>      <span class="token keyword">DATETIME</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x8003;&#x8BD5;&#x65E5;&#x671F;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>StudentResult<span class="token punctuation">`</span> <span class="token keyword">INT</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span>   <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x8003;&#x8BD5;&#x6210;&#x7EE9;&apos;</span><span class="token punctuation">,</span>
    <span class="token keyword">KEY</span> <span class="token punctuation">`</span>SubjectNo<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>SubjectNo<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span>
  <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span> <span class="token operator">=</span> utf8<span class="token punctuation">;</span>

<span class="token comment">/*Data for the table `result` */</span>

<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token punctuation">`</span>result<span class="token punctuation">`</span><span class="token punctuation">(</span><span class="token punctuation">`</span>StudentNo<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>SubjectNo<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>ExamDate<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>StudentResult<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">&apos;2013-11-11 16:00:00&apos;</span><span class="token punctuation">,</span> <span class="token number">85</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">&apos;2013-11-12 16:00:00&apos;</span><span class="token punctuation">,</span> <span class="token number">70</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token string">&apos;2013-11-11 09:00:00&apos;</span><span class="token punctuation">,</span> <span class="token number">68</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token string">&apos;2013-11-13 16:00:00&apos;</span><span class="token punctuation">,</span> <span class="token number">98</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token string">&apos;2013-11-14 16:00:00&apos;</span><span class="token punctuation">,</span> <span class="token number">58</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">/*Table structure for table `student` */</span>

<span class="token keyword">DROP</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>student<span class="token punctuation">`</span><span class="token punctuation">;</span>

<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>student<span class="token punctuation">`</span>
<span class="token punctuation">(</span>
    <span class="token punctuation">`</span>StudentNo<span class="token punctuation">`</span>    <span class="token keyword">INT</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span>       <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x5B66;&#x53F7;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>LoginPwd<span class="token punctuation">`</span>     <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>StudentName<span class="token punctuation">`</span>  <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x5B66;&#x751F;&#x59D3;&#x540D;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>Sex<span class="token punctuation">`</span>          <span class="token keyword">TINYINT</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>  <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x6027;&#x522B;&#xFF0C;0&#x6216;1&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>GradeId<span class="token punctuation">`</span>      <span class="token keyword">INT</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span>     <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x5E74;&#x7EA7;&#x7F16;&#x53F7;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>Phone<span class="token punctuation">`</span>        <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span>  <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x8054;&#x7CFB;&#x7535;&#x8BDD;&#xFF0C;&#x5141;&#x8BB8;&#x4E3A;&#x7A7A;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>Address<span class="token punctuation">`</span>      <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x5730;&#x5740;&#xFF0C;&#x5141;&#x8BB8;&#x4E3A;&#x7A7A;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>BornDate<span class="token punctuation">`</span>     <span class="token keyword">DATETIME</span>    <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x51FA;&#x751F;&#x65F6;&#x95F4;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>Email<span class="token punctuation">`</span>        <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span>  <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x90AE;&#x7BB1;&#x8D26;&#x53F7;&#x5141;&#x8BB8;&#x4E3A;&#x7A7A;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>IdentityCard<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">18</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x8EAB;&#x4EFD;&#x8BC1;&#x53F7;&apos;</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>StudentNo<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">UNIQUE</span> <span class="token keyword">KEY</span> <span class="token punctuation">`</span>IdentityCard<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>IdentityCard<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">KEY</span> <span class="token punctuation">`</span>Email<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>Email<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span> <span class="token operator">=</span> MyISAM
  <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span> <span class="token operator">=</span> utf8<span class="token punctuation">;</span>

<span class="token comment">/*Data for the table `student` */</span>

<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token punctuation">`</span>student<span class="token punctuation">`</span><span class="token punctuation">(</span><span class="token punctuation">`</span>StudentNo<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>LoginPwd<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>StudentName<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>Sex<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>GradeId<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>Phone<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>Address<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>BornDate<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>Email<span class="token punctuation">`</span><span class="token punctuation">,</span>
                      <span class="token punctuation">`</span>IdentityCard<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1000</span><span class="token punctuation">,</span> <span class="token string">&apos;123456&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x5F20;&#x4F1F;&apos;</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">&apos;13800001234&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x5317;&#x4EAC;&#x671D;&#x9633;&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;1980-01-01 00:00:00&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;text123@qq.com&apos;</span><span class="token punctuation">,</span>
        <span class="token string">&apos;123456198001011234&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">1001</span><span class="token punctuation">,</span> <span class="token string">&apos;123456&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x8D75;&#x5F3A;&apos;</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token string">&apos;13800002222&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x5E7F;&#x4E1C;&#x6DF1;&#x5733;&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;1990-01-01 00:00:00&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;text111@qq.com&apos;</span><span class="token punctuation">,</span>
        <span class="token string">&apos;123456199001011233&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">/*Table structure for table `subject` */</span>

<span class="token keyword">DROP</span> <span class="token keyword">TABLE</span> <span class="token keyword">IF</span> <span class="token keyword">EXISTS</span> <span class="token punctuation">`</span>subject<span class="token punctuation">`</span><span class="token punctuation">;</span>

<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <span class="token punctuation">`</span>subject<span class="token punctuation">`</span>
<span class="token punctuation">(</span>
    <span class="token punctuation">`</span>SubjectNo<span class="token punctuation">`</span>   <span class="token keyword">INT</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span> <span class="token keyword">AUTO_INCREMENT</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x8BFE;&#x7A0B;&#x7F16;&#x53F7;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>SubjectName<span class="token punctuation">`</span> <span class="token keyword">VARCHAR</span><span class="token punctuation">(</span><span class="token number">50</span><span class="token punctuation">)</span> <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x8BFE;&#x7A0B;&#x540D;&#x79F0;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>ClassHour<span class="token punctuation">`</span>   <span class="token keyword">INT</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span>      <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x5B66;&#x65F6;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>GradeID<span class="token punctuation">`</span>     <span class="token keyword">INT</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">)</span>      <span class="token keyword">DEFAULT</span> <span class="token boolean">NULL</span> <span class="token keyword">COMMENT</span> <span class="token string">&apos;&#x5E74;&#x7EA7;&#x7F16;&#x53F7;&apos;</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>SubjectNo<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span> <span class="token operator">=</span> <span class="token keyword">InnoDB</span>
  <span class="token keyword">DEFAULT</span> <span class="token keyword">CHARSET</span> <span class="token operator">=</span> utf8<span class="token punctuation">;</span>

<span class="token comment">/*Data for the table `subject` */</span>

<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token punctuation">`</span>subject<span class="token punctuation">`</span><span class="token punctuation">(</span><span class="token punctuation">`</span>SubjectNo<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>SubjectName<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>ClassHour<span class="token punctuation">`</span><span class="token punctuation">,</span> <span class="token punctuation">`</span>GradeID<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x9AD8;&#x7B49;&#x6570;&#x5B66;-1&apos;</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x9AD8;&#x7B49;&#x6570;&#x5B66;-2&apos;</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x9AD8;&#x7B49;&#x6570;&#x5B66;-3&apos;</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x9AD8;&#x7B49;&#x6570;&#x5B66;-4&apos;</span><span class="token punctuation">,</span> <span class="token number">130</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token string">&apos;C&#x8BED;&#x8A00;-1&apos;</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">,</span> <span class="token string">&apos;C&#x8BED;&#x8A00;-2&apos;</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">7</span><span class="token punctuation">,</span> <span class="token string">&apos;C&#x8BED;&#x8A00;-3&apos;</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">8</span><span class="token punctuation">,</span> <span class="token string">&apos;C&#x8BED;&#x8A00;-4&apos;</span><span class="token punctuation">,</span> <span class="token number">130</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">9</span><span class="token punctuation">,</span> <span class="token string">&apos;Java&#x7A0B;&#x5E8F;&#x8BBE;&#x8BA1;-1&apos;</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">&apos;Java&#x7A0B;&#x5E8F;&#x8BBE;&#x8BA1;-2&apos;</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">11</span><span class="token punctuation">,</span> <span class="token string">&apos;Java&#x7A0B;&#x5E8F;&#x8BBE;&#x8BA1;-3&apos;</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">,</span> <span class="token string">&apos;Java&#x7A0B;&#x5E8F;&#x8BBE;&#x8BA1;-4&apos;</span><span class="token punctuation">,</span> <span class="token number">130</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">13</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x6570;&#x636E;&#x5E93;&#x7ED3;&#x6784;-1&apos;</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">14</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x6570;&#x636E;&#x5E93;&#x7ED3;&#x6784;-2&apos;</span><span class="token punctuation">,</span> <span class="token number">110</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">15</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x6570;&#x636E;&#x5E93;&#x7ED3;&#x6784;-3&apos;</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">16</span><span class="token punctuation">,</span> <span class="token string">&apos;&#x6570;&#x636E;&#x5E93;&#x7ED3;&#x6784;-4&apos;</span><span class="token punctuation">,</span> <span class="token number">130</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
       <span class="token punctuation">(</span><span class="token number">17</span><span class="token punctuation">,</span> <span class="token string">&apos;C#&#x57FA;&#x7840;&apos;</span><span class="token punctuation">,</span> <span class="token number">130</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">/*!40101 SET SQL_MODE = @OLD_SQL_MODE */</span><span class="token punctuation">;</span>
<span class="token comment">/*!40014 SET FOREIGN_KEY_CHECKS = @OLD_FOREIGN_KEY_CHECKS */</span><span class="token punctuation">;</span>
<span class="token comment">/*!40014 SET UNIQUE_CHECKS = @OLD_UNIQUE_CHECKS */</span><span class="token punctuation">;</span>
<span class="token comment">/*!40111 SET SQL_NOTES = @OLD_SQL_NOTES */</span><span class="token punctuation">;</span>
</code></pre>
</div></div></div></sec>
<h2 id="31-&#x6982;&#x5FF5;"><a name="31-&#x6982;&#x5FF5;" class="anchor-navigation-ex-anchor" href="#31-&#x6982;&#x5FF5;"><i class="fa fa-link" aria-hidden="true"></i></a>3.1. &#x6982;&#x5FF5;</h2>
<p><code>DQL</code>&#xFF1A;<strong>&#x6570;&#x636E;&#x67E5;&#x8BE2;&#x8BED;&#x8A00;&#xFF08;Data Query Language&#xFF09;&#xFF0C;&#x300C;&#x67E5;&#x300D;&#x90E8;&#x5206;</strong>&#x3002;</p>
<ul>
<li><code>select</code>&#xFF1A;&#x6240;&#x6709;&#x6570;&#x636E;&#x5185;&#x5BB9;&#x7684;&#x67E5;&#x8BE2;</li>
<li><strong>&#x6838;&#x5FC3;&#x8BED;&#x53E5;&#xFF0C;&#x4F7F;&#x7528;&#x9891;&#x7387;&#x6700;&#x9AD8;&#x3002;</strong></li>
</ul>
<h2 id="32-&#x57FA;&#x7840;&#x7528;&#x6CD5;"><a name="32-&#x57FA;&#x7840;&#x7528;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#32-&#x57FA;&#x7840;&#x7528;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>3.2. &#x57FA;&#x7840;&#x7528;&#x6CD5;</h2>
<h3 id="321-&#x67E5;&#x8BE2;&#x5B57;&#x6BB5;"><a name="321-&#x67E5;&#x8BE2;&#x5B57;&#x6BB5;" class="anchor-navigation-ex-anchor" href="#321-&#x67E5;&#x8BE2;&#x5B57;&#x6BB5;"><i class="fa fa-link" aria-hidden="true"></i></a>3.2.1. &#x67E5;&#x8BE2;&#x5B57;&#x6BB5;</h3>
<ul>
<li><code>*</code>&#xFF1A;&#x8868;&#x793A;&#x67E5;&#x8BE2;&#x5168;&#x90E8;&#x5B57;&#x6BB5;<pre class="language-"><code class="lang-sql">  <span class="token keyword">select</span> <span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">1</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">2</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>  <span class="token keyword">from</span>  <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span><span class="token punctuation">;</span>
</code></pre>
</li>
</ul>
<blockquote>
<p>[!note|style:flat]
<span style="color:red;font-weight:bold"> &#x8D77;&#x4E86;&#x522B;&#x540D;&#x540E;&#xFF0C;&#x5728;&#x4E4B;&#x540E;&#x7684;<code>sql</code>&#x8BED;&#x53E5;&#x4E2D;&#xFF0C;&#x53EA;&#x80FD;&#x7528;&#x522B;&#x540D;&#x3002; </span></p>
</blockquote>
<h3 id="322-as&#x522B;&#x540D;"><a name="322-as&#x522B;&#x540D;" class="anchor-navigation-ex-anchor" href="#322-as&#x522B;&#x540D;"><i class="fa fa-link" aria-hidden="true"></i></a>3.2.2. <code>as</code>&#x522B;&#x540D;</h3>
<ul>
<li><strong>&#x53EF;&#x4EE5;&#x7ED9;&#x5B57;&#x6BB5;&#xFF0C;&#x8868;&#x540D;&#x7ED9;&#x5B9A;&#x4E00;&#x4E2A;&#x522B;&#x540D;&#xFF0C;&#x65B9;&#x4FBF;&#x67E5;&#x770B;&#x3002;</strong></li>
</ul>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> <span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">1</span><span class="token punctuation">`</span> <span class="token keyword">as</span> &#x522B;&#x540D;<span class="token punctuation">,</span><span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">2</span><span class="token punctuation">`</span> <span class="token keyword">as</span> &#x522B;&#x540D;<span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>  <span class="token keyword">from</span>  <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token keyword">as</span> &#x522B;&#x540D;<span class="token punctuation">;</span>
</code></pre>
<h3 id="323-&#x6570;&#x636E;&#x6DFB;&#x52A0;&#x5B57;&#x7B26;&#x4E32;"><a name="323-&#x6570;&#x636E;&#x6DFB;&#x52A0;&#x5B57;&#x7B26;&#x4E32;" class="anchor-navigation-ex-anchor" href="#323-&#x6570;&#x636E;&#x6DFB;&#x52A0;&#x5B57;&#x7B26;&#x4E32;"><i class="fa fa-link" aria-hidden="true"></i></a>3.2.3. &#x6570;&#x636E;&#x6DFB;&#x52A0;&#x5B57;&#x7B26;&#x4E32;</h3>
<p><strong>&#x4F5C;&#x7528;&#xFF1A;&#x7ED9;&#x67E5;&#x8BE2;&#x51FA;&#x6765;&#x7684;&#x6570;&#x636E;&#x4E2D;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x3002;</strong></p>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> concat<span class="token punctuation">(</span><span class="token string">&apos;&#x5B57;&#x7B26;&#x4E32;&apos;</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token string">&apos;&#x5B57;&#x7B26;&#x4E32;&apos;</span><span class="token punctuation">)</span> <span class="token keyword">as</span> &#x522B;&#x540D; <span class="token keyword">from</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token keyword">as</span> &#x522B;&#x540D;<span class="token punctuation">;</span>
</code></pre>
<sec data-title="&#x6848;&#x4F8B;&#x4EE3;&#x7801;" data-id="concat_example" data-show="true" data-collapse="true"><div class="panel panel-default"><div class="panel-heading"><b>&#x6848;&#x4F8B;&#x4EE3;&#x7801;<a class="pull-right section atTitle btn btn-default" target="concat_example"><span class="fa fa-angle-up"></span></a></b></div><div class="panel-collapse in" id="concat_example"><div class="panel-body">
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> CONCAT<span class="token punctuation">(</span><span class="token string">&apos;&#x79D1;&#x76EE;&#x540D;&#xFF1A;&apos;</span><span class="token punctuation">,</span><span class="token punctuation">`</span>SubjectName<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token string">&apos; fuck&apos;</span><span class="token punctuation">)</span> <span class="token keyword">from</span> subject<span class="token punctuation">;</span>
</code></pre>
</div></div></div></sec>
<h3 id="324-&#x67E5;&#x51FD;&#x6570;"><a name="324-&#x67E5;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#324-&#x67E5;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>3.2.4. &#x67E5;&#x51FD;&#x6570;</h3>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> version<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<h3 id="325-&#x6570;&#x5B66;&#x8BA1;&#x7B97;"><a name="325-&#x6570;&#x5B66;&#x8BA1;&#x7B97;" class="anchor-navigation-ex-anchor" href="#325-&#x6570;&#x5B66;&#x8BA1;&#x7B97;"><i class="fa fa-link" aria-hidden="true"></i></a>3.2.5. &#x6570;&#x5B66;&#x8BA1;&#x7B97;</h3>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> <span class="token number">2</span><span class="token operator">/</span><span class="token number">5</span> <span class="token operator">+</span> <span class="token number">1</span> <span class="token keyword">as</span> &#x7ED3;&#x679C;<span class="token punctuation">;</span>
</code></pre>
<h3 id="326-&#x67E5;&#x7CFB;&#x7EDF;&#x53D8;&#x91CF;"><a name="326-&#x67E5;&#x7CFB;&#x7EDF;&#x53D8;&#x91CF;" class="anchor-navigation-ex-anchor" href="#326-&#x67E5;&#x7CFB;&#x7EDF;&#x53D8;&#x91CF;"><i class="fa fa-link" aria-hidden="true"></i></a>3.2.6. &#x67E5;&#x7CFB;&#x7EDF;&#x53D8;&#x91CF;</h3>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> @<span class="token variable">@auto_increment_increment</span> <span class="token punctuation">;</span>
</code></pre>
<h3 id="327-&#x53BB;&#x91CD;-distinct"><a name="327-&#x53BB;&#x91CD;-distinct" class="anchor-navigation-ex-anchor" href="#327-&#x53BB;&#x91CD;-distinct"><i class="fa fa-link" aria-hidden="true"></i></a>3.2.7. &#x53BB;&#x91CD; <code>distinct</code></h3>
<p><strong>&#x4F5C;&#x7528;&#xFF1A;&#x53BB;&#x9664;<code>select</code>&#x67E5;&#x8BE2;&#x51FA;&#x6765;&#x7684;&#x91CD;&#x590D;&#x6570;&#x636E;&#x3002;</strong></p>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> <span class="token keyword">distinct</span> <span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">1</span><span class="token punctuation">`</span> <span class="token keyword">as</span> &#x522B;&#x540D;<span class="token punctuation">,</span><span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">2</span><span class="token punctuation">`</span> <span class="token keyword">as</span> &#x522B;&#x540D;<span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>  <span class="token keyword">from</span>  <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token keyword">as</span> &#x522B;&#x540D;<span class="token punctuation">;</span>
</code></pre>
<h3 id="328-&#x9009;&#x62E9;&#x6027;&#x67E5;&#x8BE2;where"><a name="328-&#x9009;&#x62E9;&#x6027;&#x67E5;&#x8BE2;where" class="anchor-navigation-ex-anchor" href="#328-&#x9009;&#x62E9;&#x6027;&#x67E5;&#x8BE2;where"><i class="fa fa-link" aria-hidden="true"></i></a>3.2.8. &#x9009;&#x62E9;&#x6027;&#x67E5;&#x8BE2;<code>where</code></h3>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> <span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">1</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">2</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>  <span class="token keyword">from</span>  <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token keyword">where</span> &#x6761;&#x4EF6;<span class="token punctuation">;</span>
</code></pre>
<h2 id="33-&#x8868;&#x8FBE;&#x5F0F;"><a name="33-&#x8868;&#x8FBE;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#33-&#x8868;&#x8FBE;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>3.3. &#x8868;&#x8FBE;&#x5F0F;</h2>
<p><strong>&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#xFF1A;</strong></p>
<ul>
<li>&#x6587;&#x672C;&#x503C;</li>
<li>&#x5217;&#x5B57;&#x6BB5;</li>
<li>Null</li>
<li>&#x51FD;&#x6570;</li>
<li>&#x8BA1;&#x7B97;&#x8868;&#x8FBE;&#x5F0F;</li>
<li>&#x7CFB;&#x7EDF;&#x53D8;&#x91CF;</li>
</ul>
<blockquote>
<p>[!note|style:flat]
<strong>&#x300C;&#x8868;&#x8FBE;&#x5F0F;&#x300D;&#x90FD;&#x80FD;&#x4F7F;&#x7528; <code>select</code> &#x8FDB;&#x884C;&#x67E5;&#x8BE2;&#x3002;</strong></p>
</blockquote>
<h1 id="4-&#x6761;&#x4EF6;&#x8FC7;&#x6EE4;where"><a name="4-&#x6761;&#x4EF6;&#x8FC7;&#x6EE4;where" class="anchor-navigation-ex-anchor" href="#4-&#x6761;&#x4EF6;&#x8FC7;&#x6EE4;where"><i class="fa fa-link" aria-hidden="true"></i></a>4. &#x6761;&#x4EF6;&#x8FC7;&#x6EE4;<code>where</code></h1>
<p><strong>&#x4F5C;&#x7528;&#xFF1A;&#x68C0;&#x6D4B;&#x5BF9;&#x5E94;&#x6761;&#x4EF6;&#x7684;&#x503C;&#x3002;</strong></p>
<ul>
<li><code>where</code>&#xFF1A;&#x67E5;&#x627E;&#x6210;&#x529F;&#xFF0C;&#x5C31;&#x6267;&#x884C;&#x6307;&#x4EE4;&#xFF1B;&#x5426;&#x5219;&#xFF0C;&#x4E0D;&#x6267;&#x884C;&#xFF0C;&#x5E76;&#x4E0D;&#x4F1A;&#x62A5;&#x9519;&#x3002;</li>
<li><code>and/or</code>&#xFF1A;&#x662F;&#x8FDE;&#x63A5;&#x4E24;&#x4E2A;&#x6761;&#x4EF6;&#x7684;&#xFF0C;&#x5BF9;&#x4E24;&#x4E2A;&#x6761;&#x4EF6;&#x7684;&#x7ED3;&#x679C;&#x8FDB;&#x884C;&#x5224;&#x5B9A;&#x3002;</li>
<li><code>()</code>&#xFF1A;&#x6539;&#x53D8;&#x6761;&#x4EF6;&#x8FD0;&#x7B97;&#x7684;&#x4F18;&#x5148;&#x7EA7;&#x3002;</li>
</ul>
<h2 id="41-&#x4E00;&#x822C;&#x6761;&#x4EF6;"><a name="41-&#x4E00;&#x822C;&#x6761;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#41-&#x4E00;&#x822C;&#x6761;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>4.1. &#x4E00;&#x822C;&#x6761;&#x4EF6;</h2>
<table>
<thead>
<tr>
<th>&#x64CD;&#x4F5C;&#x7B26;</th>
<th>&#x542B;&#x4E49;</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>=</code></td>
<td>&#x7B49;&#x4E8E;</td>
</tr>
<tr>
<td><code>&lt;&gt;,!=</code></td>
<td>&#x4E0D;&#x7B49;&#x4E8E;</td>
</tr>
<tr>
<td><code>&gt;,&lt;</code></td>
<td>&#x5927;&#x4E8E;&#xFF0C;&#x5C0F;&#x4E8E;</td>
</tr>
<tr>
<td><code>&gt;=,&lt;=</code></td>
<td>&#x4E0D;&#x5C0F;&#x4E8E;&#xFF0C;&#x4E0D;&#x5927;&#x4E8E;</td>
</tr>
<tr>
<td><code>and &amp;&amp;</code></td>
<td>&#x5E76;</td>
</tr>
<tr>
<td><code>or &#xFF5C;&#xFF5C;</code></td>
<td>&#x6216;</td>
</tr>
<tr>
<td><code>not !</code></td>
<td>&#x975E;</td>
</tr>
<tr>
<td><code>()</code></td>
<td>&#x6307;&#x5B9A;&#x4F18;&#x5148;&#x7EA7;</td>
</tr>
</tbody>
</table>
<sec data-title="&#x6848;&#x4F8B;&#x4EE3;&#x7801;" data-id="where_example" data-show="true" data-collapse="true"><div class="panel panel-default"><div class="panel-heading"><b>&#x6848;&#x4F8B;&#x4EE3;&#x7801;<a class="pull-right section atTitle btn btn-default" target="where_example"><span class="fa fa-angle-up"></span></a></b></div><div class="panel-collapse in" id="where_example"><div class="panel-body">
<pre class="language-"><code class="lang-sql"><span class="token keyword">update</span> <span class="token punctuation">`</span>student<span class="token punctuation">`</span> <span class="token keyword">set</span> <span class="token punctuation">`</span>name<span class="token punctuation">`</span><span class="token operator">=</span> <span class="token string">&apos;*&apos;</span> <span class="token keyword">where</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>age<span class="token punctuation">`</span><span class="token operator">=</span><span class="token number">29</span><span class="token punctuation">)</span> <span class="token operator">or</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>age<span class="token punctuation">`</span><span class="token operator">=</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">update</span> <span class="token punctuation">`</span>student<span class="token punctuation">`</span> <span class="token keyword">set</span> <span class="token punctuation">`</span>age<span class="token punctuation">`</span> <span class="token operator">=</span> <span class="token number">10</span> <span class="token keyword">where</span> <span class="token punctuation">`</span>age<span class="token punctuation">`</span> <span class="token operator">&lt;</span> <span class="token number">20</span><span class="token punctuation">;</span>
</code></pre>
</div></div></div></sec>
<h2 id="42-&#x6A21;&#x7CCA;&#x6761;&#x4EF6;"><a name="42-&#x6A21;&#x7CCA;&#x6761;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#42-&#x6A21;&#x7CCA;&#x6761;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>4.2. &#x6A21;&#x7CCA;&#x6761;&#x4EF6;</h2>
<table>
<thead>
<tr>
<th>&#x6761;&#x4EF6;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>is null</code></td>
<td>&#x662F;&#x5426;&#x4E3A;&#x7A7A;</td>
</tr>
<tr>
<td><code>is not null</code></td>
<td>&#x662F;&#x5426;&#x4E0D;&#x4E3A;&#x7A7A;</td>
</tr>
<tr>
<td><code>like &#x5339;&#x914D;&#x5F0F;</code></td>
<td>1. <code>%</code>: &#x7C7B;&#x4F3C;<code>*</code>&#xFF0C;&#x901A;&#x914D;&#x6240;&#x6709; <br>  2. <code>_</code>&#xFF1A;<strong>&#x4E00;&#x4E2A;&#x5B57;&#x7B26;</strong></td>
</tr>
<tr>
<td><code>in (&#x503C;1,&#x503C;2,&#x503C;3...)</code></td>
<td>&#x5728;<code>()</code>&#x4E2D;&#x662F;&#x5426;&#x5B58;&#x5728;</td>
</tr>
<tr>
<td><code>between a and b</code></td>
<td>&#x662F;&#x5426;&#x5728;[a,b]&#x533A;&#x95F4;&#x5185;</td>
</tr>
</tbody>
</table>
<sec data-title="&#x6848;&#x4F8B;&#x4EE3;&#x7801;" data-id="search_fuzzy" data-show="true" data-collapse="true"><div class="panel panel-default"><div class="panel-heading"><b>&#x6848;&#x4F8B;&#x4EE3;&#x7801;<a class="pull-right section atTitle btn btn-default" target="search_fuzzy"><span class="fa fa-angle-up"></span></a></b></div><div class="panel-collapse in" id="search_fuzzy"><div class="panel-body">
<pre class="language-"><code class="lang-sql"><span class="token comment">-- in &#x67E5;&#x627E;</span>
<span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">from</span> result <span class="token keyword">where</span> <span class="token punctuation">`</span>SubjectNo<span class="token punctuation">`</span> <span class="token operator">in</span> <span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">-- &#x5224;&#x65AD;&#x662F;&#x5426;&#x4E3A; null</span>
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> result <span class="token keyword">where</span> <span class="token punctuation">`</span>ExamDate<span class="token punctuation">`</span> <span class="token operator">is</span> <span class="token operator">not</span> <span class="token boolean">null</span><span class="token punctuation">;</span>
<span class="token comment">-- like &#x5339;&#x914D;&#x67E5;&#x627E;</span>
<span class="token keyword">select</span> <span class="token punctuation">`</span>StudentName<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>LoginPwd<span class="token punctuation">`</span> <span class="token keyword">from</span> student <span class="token keyword">WHERE</span> <span class="token punctuation">`</span>Address<span class="token punctuation">`</span> <span class="token operator">like</span> <span class="token string">&apos;&#x5317;&#x4EAC;%&apos;</span><span class="token punctuation">;</span>
</code></pre>
</div></div></div></sec>
<blockquote>
<p>[!note|style:flat]</p>
<ul>
<li><strong>&#x4E0D;&#x80FD;&#x4F7F;&#x7528;<code>where &#x5B57;&#x6BB5; = null</code>&#xFF0C;&#x5F97;&#x7528;<code>where &#x5B57;&#x6BB5; is null</code></strong></li>
<li><strong><code>in</code> &#x4E0E; <code>=</code></strong><ul>
<li><strong>&#x7ED3;&#x679C;&#x96C6;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x503C;&#x65F6;&#xFF1A;<code>A = B</code> &#x4E0E; <code>A in (&apos;B&apos;)</code> &#x7B49;&#x4EF7;&#x3002;</strong></li>
<li><strong>&#x7ED3;&#x679C;&#x96C6;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x503C;&#x65F6;&#xFF1A;<code>A = B or A = C</code> &#x4E0E;<code>A in (B,C)</code>&#x7B49;&#x4EF7;&#x3002;</strong></li>
</ul>
</li>
</ul>
</blockquote>
<h1 id="5-&#x8054;&#x8868;&#x67E5;&#x8BE2;"><a name="5-&#x8054;&#x8868;&#x67E5;&#x8BE2;" class="anchor-navigation-ex-anchor" href="#5-&#x8054;&#x8868;&#x67E5;&#x8BE2;"><i class="fa fa-link" aria-hidden="true"></i></a>5. &#x8054;&#x8868;&#x67E5;&#x8BE2;</h1>
<h2 id="51-&#x6982;&#x5FF5;"><a name="51-&#x6982;&#x5FF5;" class="anchor-navigation-ex-anchor" href="#51-&#x6982;&#x5FF5;"><i class="fa fa-link" aria-hidden="true"></i></a>5.1. &#x6982;&#x5FF5;</h2>
<p><strong>&#x4F5C;&#x7528;&#xFF1A;&#x5BF9;&#x300C;&#x4E24;&#x5F20;&#x8868;&#x300D;&#x8FDB;&#x884C;&#x8054;&#x5408;&#x67E5;&#x8BE2;&#xFF0C;&#x5229;&#x7528;&#x4E24;&#x5F20;&#x8868;&#x7684;&#x300C;&#x76F8;&#x540C;&#x7684;&#x5B57;&#x6BB5;&#x300D;&#x8FDB;&#x884C;&#x8FDE;&#x63A5;&#xFF0C;&#x7136;&#x540E;&#x5C06;&#x67E5;&#x8BE2;&#x7ED3;&#x679C;&#x4F5C;&#x4E3A;&#x300C;&#x5F53;&#x4F5C;&#x4E00;&#x5F20;&#x8868;&#x300D;&#x8F93;&#x51FA;&#x3002;</strong></p>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> a&#x7684;&#x5B57;&#x6BB5;<span class="token punctuation">,</span>b&#x7684;&#x5B57;&#x6BB5; <span class="token punctuation">(</span>&#x5168;&#x90E8;&#x8981;&#x8F93;&#x51FA;&#x7684;&#x5B57;&#x6BB5;<span class="token punctuation">)</span>
<span class="token keyword">from</span> tableA <span class="token punctuation">[</span><span class="token keyword">as</span><span class="token punctuation">]</span> a
&#x65B9;&#x5F0F; <span class="token keyword">join</span> tableB <span class="token punctuation">[</span><span class="token keyword">as</span><span class="token punctuation">]</span> b
<span class="token keyword">on</span> &#x4E24;&#x5F20;&#x8868;&#x7684;&#x8FDE;&#x63A5;&#x6761;&#x4EF6;&#x5B57;&#x6BB5;

<span class="token keyword">where</span> &#x5BF9;&#x6700;&#x7EC8;&#x5408;&#x6210;&#x8868;&#xFF0C;&#x518D;&#x8FDB;&#x884C;&#x67E5;&#x8BE2; <span class="token punctuation">;</span>
</code></pre>
<blockquote>
<p>[!note|style:flat]</p>
<ul>
<li><strong><code>tableA , tableB</code>&#xFF1A;&#x4E24;&#x5F20;&#x8868;&#x6839;&#x636E;&#x5199;&#x7684;&#x5148;&#x540E;&#x987A;&#x5E8F;&#xFF0C;&#x5177;&#x6709;&#x5DE6;&#x53F3;&#x4E4B;&#x5206;&#x3002;</strong></li>
<li><strong><code>tableA [as] a</code>&#xFF1A;<code>as</code>&#x53EF;&#x4EE5;&#x7701;&#x7565;&#x4E0D;&#x5199;</strong></li>
<li><strong><code>join on</code>&#xFF1A;&#x53EF;&#x4EE5;&#x5C06;&#x67E5;&#x8BE2;&#x7684;&#x7ED3;&#x679C;&#x4F5C;&#x4E3A;&#x4E00;&#x5F20;&#x8868;&#xFF0C;&#x518D;&#x4E0E;&#x7B2C;&#x4E09;&#x5F20;&#x8868;<code>tableC</code>&#x8FDB;&#x884C;&#x94FE;&#x63A5;</strong></li>
<li><strong><code>&#x8868;&#x540D;/&#x522B;&#x540D;.&#x5B57;&#x6BB5;</code>&#xFF1A;&#x53EF;&#x4EE5;&#x5BF9;&#x91CD;&#x590D;&#x7684;&#x5B57;&#x6BB5;&#x540D;&#x8FDB;&#x884C;&#x533A;&#x522B;&#x3002;</strong></li>
<li><span style="color:red;font-weight:bold"> &#x67E5;&#x8BE2;&#x7ED3;&#x679C;&#xFF1A;&#x4EE5;&#x6307;&#x5B9A;&#x300C;&#x8FDE;&#x63A5;&#x65B9;&#x5F0F;&#x300D;&#x62FC;&#x63A5;&#x51FA;&#x4E00;&#x4E2A;&#x300C;&#x57FA;&#x51C6;&#x8868;&#x300D;&#xFF1B;&#x7136;&#x540E;&#x518D;&#x5BF9;<code>select</code>&#x5B57;&#x6BB5;&#x7684;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x9009;&#x62E9;&#xFF0C;&#x5E76;&#x5C06;&#x5C06;&#x9009;&#x62E9;&#x7ED3;&#x679C;&#x300C;&#x5F53;&#x4F5C;&#x4E00;&#x5F20;&#x65B0;&#x7684;&#x8868;&#x300D;&#xFF1B;&#x6700;&#x540E;&#x901A;&#x8FC7;<code>where</code>&#x7B5B;&#x9009;&#x6570;&#x636E;&#x3002; </span></li>
</ul>
</blockquote>
<sec data-title="&#x6848;&#x4F8B;&#x4EE3;&#x7801;" data-id="joinon_example" data-show="true" data-collapse="true"><div class="panel panel-default"><div class="panel-heading"><b>&#x6848;&#x4F8B;&#x4EE3;&#x7801;<a class="pull-right section atTitle btn btn-default" target="joinon_example"><span class="fa fa-angle-up"></span></a></b></div><div class="panel-collapse in" id="joinon_example"><div class="panel-body">
<pre class="language-"><code class="lang-sql"><span class="token comment">-- &#x6240;&#x6709;&#x9700;&#x8981;&#x67E5;&#x770B;&#x7684;&#x5B57;&#x6BB5;</span>
<span class="token keyword">select</span> stu<span class="token punctuation">.</span><span class="token punctuation">`</span>StudentNo<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>StudentName<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>StudentResult<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>SubjectName<span class="token punctuation">`</span> 
<span class="token comment">-- &#x5148;&#x8FDE;&#x4E24;&#x5F20;&#x8868;</span>
<span class="token keyword">from</span> student <span class="token keyword">as</span> stu
<span class="token keyword">LEFT</span> <span class="token keyword">join</span> result <span class="token keyword">as</span> res
<span class="token keyword">on</span> stu<span class="token punctuation">.</span>StudentNo <span class="token operator">=</span> res<span class="token punctuation">.</span>StudentNo
<span class="token comment">-- &#x8FDE;&#x7B2C;&#x4E09;&#x5F20;&#x8868;</span>
<span class="token keyword">inner</span> <span class="token keyword">join</span> subject 
<span class="token keyword">on</span> subject<span class="token punctuation">.</span>SubjectNo <span class="token operator">=</span> res<span class="token punctuation">.</span>SubjectNo
<span class="token comment">-- &#x67E5;&#x8BE2;</span>
<span class="token keyword">where</span> subject<span class="token punctuation">.</span>SubjectName <span class="token operator">like</span> <span class="token string">&apos;c%&apos;</span><span class="token punctuation">;</span>
</code></pre>
</div></div></div></sec>
<h2 id="52-&#x8FDE;&#x63A5;&#x65B9;&#x5F0F;"><a name="52-&#x8FDE;&#x63A5;&#x65B9;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#52-&#x8FDE;&#x63A5;&#x65B9;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>5.2. &#x8FDE;&#x63A5;&#x65B9;&#x5F0F;</h2>
<p style="text-align:center;"><a href="../../image/mysql/joinon.png" data-lightbox="7f7daf4f-fe26-49e3-b5c6-d459e5372221" data-title="undefined"><img src="../../image/mysql/joinon.png" alt="undefined"></a></p>

<table>
<thead>
<tr>
<th>&#x65B9;&#x5F0F;</th>
<th>&#x5B57;&#x6BB5;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>inner</code></td>
<td><code>from A iner join B on A.key = B.key</code></td>
<td><code>A</code>&#x8868;&#x4E0E;<code>B</code>&#x8868;&#x7684;<code>key</code>&#xFF0C;&#x4EE5;&#x4E24;&#x8FB9;&#x90FD;&#x6709;&#x7684;<code>key</code>&#x4F5C;&#x4E3A;&#x57FA;&#x51C6;</td>
</tr>
<tr>
<td><code>left</code></td>
<td><code>from A left join B on A.key = B.key</code></td>
<td><code>A</code>&#x8868;&#x4E0E;<code>B</code>&#x8868;&#x7684;<code>key</code>&#xFF0C;&#x4EE5;<code>left</code>&#x8868;&#xFF08;<code>A</code>&#xFF09;&#x7684;&#x6240;&#x6709; <code>A.key</code>&#x4F5C;&#x4E3A;&#x57FA;&#x51C6;</td>
</tr>
<tr>
<td><code>right</code></td>
<td><code>from A right join B on A.key = B.key</code></td>
<td><code>A</code>&#x8868;&#x4E0E;<code>B</code>&#x8868;&#x7684;<code>key</code>&#xFF0C;&#x4EE5;<code>right</code>&#x8868;&#xFF08;<code>B</code>&#xFF09;&#x7684;&#x6240;&#x6709;<code>B.key</code>&#x4F5C;&#x4E3A;&#x57FA;&#x51C6;</td>
</tr>
</tbody>
</table>
<blockquote>
<p>[!note|style:flat]
<span style="color:red;font-weight:bold"> &#x300C;&#x8FDE;&#x63A5;&#x65B9;&#x5F0F;&#x300D;&#x53EA;&#x662F;&#x62FC;&#x63A5;&#x51FA;&#x4E00;&#x4E2A;&#x300C;&#x5305;&#x542B;&#x4E24;&#x4E2A;&#x8868;&#x6240;&#x6709;&#x5B57;&#x6BB5;&#x7684;&#x57FA;&#x51C6;&#x8868;&#xFF08;&#x540C;&#x540D;&#x5B57;&#x6BB5;&#xFF0C;<code>A.name</code>&#x4E0E;<code>B.name</code>&#xFF0C;&#x7B97;&#x4E24;&#x4E2A;&#x5B57;&#x6BB5;&#xFF09;&#x300D;&#xFF0C;&#x5B9E;&#x9645;&#x8F93;&#x51FA;&#x8FD8;&#x5F97;&#x6839;&#x636E;&#x300C;<code>select</code>&#x5B57;&#x6BB5;&#x300D;&#x6765;&#x3002; </span></p>
</blockquote>
<h1 id="6-&#x81EA;&#x8FDE;&#x67E5;&#x8BE2;&#xFF08;&#x4E86;&#x89E3;&#xFF09;"><a name="6-&#x81EA;&#x8FDE;&#x67E5;&#x8BE2;&#xFF08;&#x4E86;&#x89E3;&#xFF09;" class="anchor-navigation-ex-anchor" href="#6-&#x81EA;&#x8FDE;&#x67E5;&#x8BE2;&#xFF08;&#x4E86;&#x89E3;&#xFF09;"><i class="fa fa-link" aria-hidden="true"></i></a>6. &#x81EA;&#x8FDE;&#x67E5;&#x8BE2;&#xFF08;&#x4E86;&#x89E3;&#xFF09;</h1>
<p><strong>&#x4F5C;&#x7528;&#xFF1A;&#x5C06;&#x4E00;&#x5F20;&#x8868;&#xFF0C;&#x5F53;&#x4F5C;&#x662F;&#x4E24;&#x5F20;&#x8868;&#xFF0C;&#x7136;&#x540E;&#x8FDB;&#x884C;&#x8054;&#x8868;&#x67E5;&#x8BE2;&#x3002;</strong></p>
<p><strong>&#x8981;&#x6C42;&#xFF1A;&#x5C06;&#x8868;&#x4E2D;&#x7684;&#x5404;&#x9879;&#xFF0C;&#x6839;&#x636E;&#x5C42;&#x7EA7;&#x5173;&#x7CFB;&#x663E;&#x793A;&#x51FA;&#x6765;&#x3002;&#x8868;&#xFF1A;</strong></p>
<p style="text-align:center;"><a href="../../image/mysql/self_query_table.png" data-lightbox="8754d193-aef8-4c0a-833e-673c43dbb500" data-title="undefined"><img src="../../image/mysql/self_query_table.png" alt="undefined"></a></p>

<p><strong>&#x67E5;&#x8BE2;&#x7ED3;&#x679C;&#xFF1A;</strong></p>
<p style="text-align:center;"><a href="../../image/mysql/self_query_result.png" data-lightbox="ab3dcd59-79f5-4b5d-96f1-41f93f0dc458" data-title="undefined"><img src="../../image/mysql/self_query_result.png" alt="undefined"></a></p>

<sec data-title="&#x6848;&#x4F8B;" data-id="self_query" data-show="true" data-collapse="true"><div class="panel panel-default"><div class="panel-heading"><b>&#x6848;&#x4F8B;<a class="pull-right section atTitle btn btn-default" target="self_query"><span class="fa fa-angle-up"></span></a></b></div><div class="panel-collapse in" id="self_query"><div class="panel-body">
<pre class="language-"><code class="lang-sql"><span class="token comment">-- &#x5EFA;&#x8868;</span>
<span class="token keyword">create</span> <span class="token keyword">table</span> <span class="token punctuation">`</span>schoolStruct<span class="token punctuation">`</span><span class="token punctuation">(</span>
    <span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span>  <span class="token keyword">auto_increment</span> <span class="token keyword">comment</span> <span class="token string">&apos;id&#x53F7;&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>pid<span class="token punctuation">`</span> <span class="token keyword">int</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span> <span class="token operator">not</span> <span class="token boolean">NULL</span> <span class="token keyword">default</span> <span class="token number">0</span> <span class="token keyword">comment</span> <span class="token string">&apos;&#x7236;id&apos;</span><span class="token punctuation">,</span>
    <span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">varchar</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span> <span class="token keyword">default</span> <span class="token boolean">NULL</span> <span class="token keyword">comment</span> <span class="token string">&apos;&#x540D;&#x79F0;&apos;</span><span class="token punctuation">,</span>
    <span class="token keyword">primary</span> <span class="token keyword">key</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span><span class="token keyword">engine</span><span class="token operator">=</span><span class="token keyword">innodb</span> <span class="token keyword">charset</span><span class="token operator">=</span>utf8<span class="token punctuation">;</span>

<span class="token comment">-- &#x63D2;&#x5165;&#x6570;&#x636E;</span>
<span class="token keyword">insert</span> <span class="token keyword">into</span> <span class="token punctuation">`</span>schoolStruct<span class="token punctuation">`</span> <span class="token punctuation">(</span><span class="token punctuation">`</span>pid<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>name<span class="token punctuation">`</span><span class="token punctuation">)</span> <span class="token keyword">values</span> 
<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token string">&apos;&#x5357;&#x4EAC;&#x7406;&#x5DE5;&#x5927;&#x5B66;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token string">&apos;&#x80FD;&#x52A8;&#x9662;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token string">&apos;&#x91CD;&#x70B9;&#x5B9E;&#x9A8C;&#x5BA4;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token string">&apos;802&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token string">&apos;801&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token string">&apos;808&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">-- &#x81EA;&#x8FDE;&#x67E5;&#x8BE2;</span>
<span class="token keyword">select</span> p<span class="token punctuation">.</span><span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">as</span> <span class="token string">&apos;&#x7236;&apos;</span><span class="token punctuation">,</span>s<span class="token punctuation">.</span><span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token keyword">as</span> <span class="token string">&apos;&#x5B50;&apos;</span>
<span class="token keyword">from</span> <span class="token punctuation">`</span>schoolStruct<span class="token punctuation">`</span> <span class="token keyword">as</span> p<span class="token punctuation">,</span><span class="token punctuation">`</span>schoolStruct<span class="token punctuation">`</span> <span class="token keyword">as</span> s
<span class="token keyword">where</span> p<span class="token punctuation">.</span><span class="token punctuation">`</span>id<span class="token punctuation">`</span> <span class="token operator">=</span> s<span class="token punctuation">.</span><span class="token punctuation">`</span>pid<span class="token punctuation">`</span><span class="token punctuation">;</span>
</code></pre>
</div></div></div></sec>
<h1 id="7-&#x5206;&#x7EC4;-group-by"><a name="7-&#x5206;&#x7EC4;-group-by" class="anchor-navigation-ex-anchor" href="#7-&#x5206;&#x7EC4;-group-by"><i class="fa fa-link" aria-hidden="true"></i></a>7. &#x5206;&#x7EC4; <code>group by</code></h1>
<p><strong>&#x4F5C;&#x7528;&#xFF1A;&#x901A;&#x8FC7;&#x90A3;&#x4E00;&#x4E2A;&#x5B57;&#x6BB5;&#x8FDB;&#x884C;&#x5206;&#x7EC4;&#xFF0C;&#x503C;&#x4E00;&#x6837;&#x7684;&#x5206;&#x4E3A;&#x4E00;&#x7EC4;&#x3002;</strong></p>
<h1 id="8-&#x7EC4;&#x8FC7;&#x6EE4;-having"><a name="8-&#x7EC4;&#x8FC7;&#x6EE4;-having" class="anchor-navigation-ex-anchor" href="#8-&#x7EC4;&#x8FC7;&#x6EE4;-having"><i class="fa fa-link" aria-hidden="true"></i></a>8. &#x7EC4;&#x8FC7;&#x6EE4; <code>having</code></h1>
<blockquote>
<p>[!note|style:flat]
<strong>&#x5206;&#x7EC4;&#x4E4B;&#x540E;&#x7684;&#x6570;&#x636E;&#x8868;&#xFF0C;&#x4E0D;&#x80FD;&#x518D;&#x4F7F;&#x7528;<code>where</code>&#x8FDB;&#x884C;&#x8FC7;&#x6EE4;&#xFF0C;&#x5FC5;&#x987B;&#x8981;&#x7528;<code>having</code>&#x3002;</strong></p>
</blockquote>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> <span class="token punctuation">`</span>subjectName<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token function">AVG</span><span class="token punctuation">(</span><span class="token punctuation">`</span>studentResult<span class="token punctuation">`</span><span class="token punctuation">)</span> <span class="token keyword">as</span> <span class="token punctuation">`</span>mean<span class="token punctuation">`</span> <span class="token punctuation">,</span><span class="token function">max</span><span class="token punctuation">(</span><span class="token punctuation">`</span>studentResult<span class="token punctuation">`</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token function">min</span><span class="token punctuation">(</span><span class="token punctuation">`</span>studentResult<span class="token punctuation">`</span><span class="token punctuation">)</span>
<span class="token keyword">from</span> <span class="token punctuation">`</span>result<span class="token punctuation">`</span> r
<span class="token keyword">inner</span> <span class="token keyword">join</span> <span class="token punctuation">`</span>subject<span class="token punctuation">`</span> sub
<span class="token keyword">on</span> r<span class="token punctuation">.</span>SubjectNo <span class="token operator">=</span> sub<span class="token punctuation">.</span>SubjectNo

<span class="token comment">-- &#x6240;&#x6709;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x8FC7;&#x6EE4;</span>
<span class="token keyword">where</span> r<span class="token punctuation">.</span>StudentResult <span class="token operator">&gt;</span> <span class="token number">20</span>

<span class="token keyword">group</span> <span class="token keyword">by</span> sub<span class="token punctuation">.</span>SubjectName

<span class="token comment">-- &#x5206;&#x7EC4;&#x4E4B;&#x540E;&#x7684;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x8FC7;&#x6EE4;</span>
<span class="token keyword">having</span> <span class="token punctuation">`</span>mean<span class="token punctuation">`</span> <span class="token operator">&gt;</span> <span class="token number">60</span>

<span class="token keyword">order</span> <span class="token keyword">by</span> <span class="token punctuation">`</span>mean<span class="token punctuation">`</span> <span class="token keyword">desc</span><span class="token punctuation">;</span>
</code></pre>
<h1 id="9-&#x6392;&#x5E8F;order-by"><a name="9-&#x6392;&#x5E8F;order-by" class="anchor-navigation-ex-anchor" href="#9-&#x6392;&#x5E8F;order-by"><i class="fa fa-link" aria-hidden="true"></i></a>9. &#x6392;&#x5E8F;<code>order by</code></h1>
<p><strong>&#x4F5C;&#x7528;&#xFF1A;&#x5BF9;&#x6570;&#x636E;&#x6392;&#x5E8F;&#x3002;</strong></p>
<ul>
<li><code>asc (ascending)</code>&#xFF1A;<strong>&#x4ECE;&#x4E0A;&#x5F80;&#x4E0B;&#xFF0C;&#x4ECE;&#x5C0F;&#x5230;&#x5927;</strong></li>
<li><code>desc (descending)</code>&#xFF1A;<strong>&#x4ECE;&#x4E0A;&#x5F80;&#x4E0B;&#xFF0C;&#x4ECE;&#x5927;&#x5230;&#x5C0F;</strong></li>
</ul>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token keyword">ORDER</span> <span class="token keyword">BY</span> <span class="token punctuation">`</span>&#x6392;&#x5E8F;&#x5B57;&#x6BB5;<span class="token punctuation">`</span> <span class="token keyword">desc</span><span class="token punctuation">;</span>
</code></pre>
<h1 id="10-&#x5206;&#x9875;limit"><a name="10-&#x5206;&#x9875;limit" class="anchor-navigation-ex-anchor" href="#10-&#x5206;&#x9875;limit"><i class="fa fa-link" aria-hidden="true"></i></a>10. &#x5206;&#x9875;<code>limit</code></h1>
<p><strong>&#x4F5C;&#x7528;&#xFF1A;&#x90E8;&#x5206;&#x663E;&#x793A;&#x8868;</strong></p>
<ul>
<li><span style="color:red;font-weight:bold"> <code>limit</code> &#x53EA;&#x80FD;&#x653E;&#x6700;&#x540E;&#x3002; </span></li>
<li><strong><code>limit</code>&#xFF1A;&#x7D22;&#x5F15;&#x4ECE; <code>0</code> &#x5F00;&#x59CB;&#x3002;</strong></li>
</ul>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token punctuation">`</span> <span class="token keyword">limit</span> &#x8D77;&#x59CB;&#x7D22;&#x5F15;<span class="token punctuation">,</span>&#x663E;&#x793A;&#x884C;&#x6570;<span class="token punctuation">;</span>
</code></pre>
<h1 id="11-&#x5D4C;&#x5957;&#x67E5;&#x8BE2;"><a name="11-&#x5D4C;&#x5957;&#x67E5;&#x8BE2;" class="anchor-navigation-ex-anchor" href="#11-&#x5D4C;&#x5957;&#x67E5;&#x8BE2;"><i class="fa fa-link" aria-hidden="true"></i></a>11. &#x5D4C;&#x5957;&#x67E5;&#x8BE2;</h1>
<p><strong>&#x5BF9;&#x4E8E;<code>where &#x6761;&#x4EF6;</code>&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;<code>&#x6761;&#x4EF6;</code>&#x4FEE;&#x6539;&#x4E3A;&#x67E5;&#x8BE2;&#x8BED;&#x53E5;<code>select</code>&#x3002;</strong></p>
<pre class="language-"><code class="lang-sql"><span class="token comment">/* c&#x8BED;&#x8A00;&#x8BFE;&#x6210;&#x7EE9;&#x6700;&#x597D;&#x7684;&#xFF0C;&#x663E;&#x793A;&#x540D;&#x5B57;&#xFF0C;&#x5B66;&#x53F7; */</span>

<span class="token comment">-- &#x6700;&#x540E;&#x663E;&#x793A;&#x7684;&#x7ED3;&#x679C;</span>
<span class="token keyword">select</span> <span class="token punctuation">`</span>studentNo<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>studentName<span class="token punctuation">`</span> <span class="token keyword">from</span> <span class="token punctuation">`</span>student<span class="token punctuation">`</span> 
<span class="token keyword">where</span> <span class="token punctuation">`</span>studentNo<span class="token punctuation">`</span> <span class="token operator">=</span> <span class="token punctuation">(</span>
    <span class="token comment">-- &#x5BF9;c&#x8BED;&#x8A00;&#x6210;&#x7EE9;&#x8FDB;&#x884C;&#x6392;&#x5E8F;</span>
    <span class="token keyword">select</span> <span class="token punctuation">`</span>studentNo<span class="token punctuation">`</span> <span class="token keyword">from</span> <span class="token punctuation">`</span>result<span class="token punctuation">`</span> 
    <span class="token keyword">where</span> <span class="token punctuation">`</span>subjectNo<span class="token punctuation">`</span> <span class="token operator">in</span> <span class="token punctuation">(</span>
        <span class="token comment">-- &#x67E5;&#x8BE2;c&#x8BED;&#x8A00;&#x8BFE;&#x7A0B;</span>
        <span class="token keyword">select</span> <span class="token punctuation">`</span>subjectNo<span class="token punctuation">`</span> <span class="token keyword">from</span> <span class="token punctuation">`</span>subject<span class="token punctuation">`</span>
        <span class="token keyword">where</span> <span class="token punctuation">`</span>subjectName<span class="token punctuation">`</span> <span class="token operator">like</span> <span class="token string">&apos;c%&apos;</span>
    <span class="token punctuation">)</span>
    <span class="token comment">-- &#x6392;&#x5E8F;</span>
    <span class="token keyword">order</span> <span class="token keyword">by</span> <span class="token punctuation">`</span>StudentResult<span class="token punctuation">`</span> <span class="token keyword">desc</span>
    <span class="token comment">-- &#x53D6;&#x51FA;&#x7B2C;&#x4E00;&#x4E2A;</span>
    <span class="token keyword">limit</span> <span class="token number">0</span><span class="token punctuation">,</span><span class="token number">1</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<blockquote>
<p>[!note|style:flat]
<span style="color:red;font-weight:bold"> &#x8BE5;&#x65B9;&#x6CD5;&#xFF0C;&#x53EA;&#x80FD;&#x7528;&#x4E8E;&#x6700;&#x7EC8;&#x7ED3;&#x679C;&#x90FD;&#x5728;&#x4E00;&#x5F20;&#x8868;&#x4E0A;&#x7684;&#x4E1A;&#x52A1;&#x3002; </span></p>
</blockquote>
<h1 id="12-&#x51FD;&#x6570;"><a name="12-&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#12-&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>12. &#x51FD;&#x6570;</h1>
<h2 id="121-&#x5E38;&#x7528;&#x51FD;&#x6570;"><a name="121-&#x5E38;&#x7528;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#121-&#x5E38;&#x7528;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>12.1. &#x5E38;&#x7528;&#x51FD;&#x6570;</h2>
<h3 id="1211-&#x6570;&#x5B66;"><a name="1211-&#x6570;&#x5B66;" class="anchor-navigation-ex-anchor" href="#1211-&#x6570;&#x5B66;"><i class="fa fa-link" aria-hidden="true"></i></a>12.1.1. &#x6570;&#x5B66;</h3>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> abs<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x7EDD;&#x5BF9;&#x503C;</span>
<span class="token keyword">select</span> ceiling<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x5411;&#x4E0A;&#x53D6;&#x6574;</span>
<span class="token keyword">select</span> floor<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x5411;&#x4E0B;</span>
<span class="token keyword">select</span> rand<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x968F;&#x673A;&#x6570; 0 ~ 1</span>
<span class="token keyword">select</span> sign<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x6570;&#x7684;&#x7B26;&#x53F7;</span>
</code></pre>
<h3 id="1212-&#x5B57;&#x7B26;&#x4E32;"><a name="1212-&#x5B57;&#x7B26;&#x4E32;" class="anchor-navigation-ex-anchor" href="#1212-&#x5B57;&#x7B26;&#x4E32;"><i class="fa fa-link" aria-hidden="true"></i></a>12.1.2. &#x5B57;&#x7B26;&#x4E32;</h3>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> char_length<span class="token punctuation">(</span><span class="token string">&apos;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x5B57;&#x7B26;&#x4E32;&#x957F;&#x5EA6;</span>
<span class="token keyword">select</span> concat<span class="token punctuation">(</span><span class="token string">&apos;&apos;</span><span class="token punctuation">,</span><span class="token string">&apos;&apos;</span><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x5B57;&#x7B26;&#x4E32;&#x62FC;&#x63A5;</span>
<span class="token keyword">select</span> <span class="token keyword">insert</span><span class="token punctuation">(</span>src<span class="token punctuation">,</span>pos<span class="token punctuation">,</span>len<span class="token punctuation">,</span>dest<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x5BF9;src&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5C06;pos&#x5F00;&#x59CB;&#x7684;len&#x4E2A;&#x5B57;&#x7B26;&#xFF0C;&#x66FF;&#x6362;&#x4E3A;dest</span>
<span class="token keyword">select</span> lower<span class="token punctuation">(</span><span class="token string">&apos;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x8F6C;&#x5C0F;&#x5199;</span>
<span class="token keyword">select</span> upper<span class="token punctuation">(</span><span class="token string">&apos;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x8F6C;&#x5927;&#x5199;</span>
</code></pre>
<h3 id="1213-&#x65F6;&#x95F4;"><a name="1213-&#x65F6;&#x95F4;" class="anchor-navigation-ex-anchor" href="#1213-&#x65F6;&#x95F4;"><i class="fa fa-link" aria-hidden="true"></i></a>12.1.3. &#x65F6;&#x95F4;</h3>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> <span class="token keyword">current_date</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x83B7;&#x53D6;&#x5F53;&#x524D;&#x65E5;&#x671F;</span>
<span class="token keyword">select</span> <span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x5F53;&#x524D;&#x65F6;&#x95F4;</span>
<span class="token keyword">select</span> localtime<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x672C;&#x5730;&#x65F6;&#x95F4;</span>
<span class="token keyword">select</span> sysdate<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x7CFB;&#x7EDF;&#x65F6;&#x95F4;</span>
<span class="token keyword">select</span> <span class="token keyword">year</span><span class="token operator">/</span><span class="token keyword">month</span><span class="token operator">/</span><span class="token keyword">hour</span><span class="token punctuation">(</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">-- &#x89E3;&#x6790;&#x65F6;&#x95F4;</span>
</code></pre>
<h3 id="1214-&#x7CFB;&#x7EDF;"><a name="1214-&#x7CFB;&#x7EDF;" class="anchor-navigation-ex-anchor" href="#1214-&#x7CFB;&#x7EDF;"><i class="fa fa-link" aria-hidden="true"></i></a>12.1.4. &#x7CFB;&#x7EDF;</h3>
<pre class="language-"><code class="lang-sql"><span class="token keyword">select</span> <span class="token keyword">system_user</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">select</span> <span class="token keyword">user</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">select</span> version<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<h2 id="122-&#x805A;&#x5408;&#x51FD;&#x6570;&#xFF08;&#x91CD;&#x8981;&#xFF09;"><a name="122-&#x805A;&#x5408;&#x51FD;&#x6570;&#xFF08;&#x91CD;&#x8981;&#xFF09;" class="anchor-navigation-ex-anchor" href="#122-&#x805A;&#x5408;&#x51FD;&#x6570;&#xFF08;&#x91CD;&#x8981;&#xFF09;"><i class="fa fa-link" aria-hidden="true"></i></a>12.2. &#x805A;&#x5408;&#x51FD;&#x6570;&#xFF08;&#x91CD;&#x8981;&#xFF09;</h2>
<table>
<thead>
<tr>
<th>&#x51FD;&#x6570;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>count()</code></td>
<td>&#x8BA1;&#x6570;</td>
</tr>
<tr>
<td><code>sum()</code></td>
<td>&#x6C42;&#x548C;</td>
</tr>
<tr>
<td><code>avg()</code></td>
<td>&#x5747;&#x503C;</td>
</tr>
<tr>
<td><code>max()</code></td>
<td>&#x6700;&#x5927;</td>
</tr>
<tr>
<td><code>min()</code></td>
<td>&#x6700;&#x5C0F;</td>
</tr>
</tbody>
</table>
<h3 id="1221-count"><a name="1221-count" class="anchor-navigation-ex-anchor" href="#1221-count"><i class="fa fa-link" aria-hidden="true"></i></a>12.2.1. <code>count()</code></h3>
<ul>
<li><code>count(&#x5B57;&#x6BB5;)</code>&#xFF1A;&#x4F1A;&#x5FFD;&#x7565;&#x6240;&#x90E8;&#x7684;<code>null</code>&#x3002;</li>
<li><code>count(*)</code>&#xFF1A;&#x4E0D;&#x4F1A;&#x5FFD;&#x7565;<code>null</code>&#xFF0C;&#x8FD4;&#x56DE;&#x8868;&#x7684;&#x300C;&#x884C;&#x6570;&#x300D;&#x3002;</li>
<li><code>count(1)</code>&#xFF1A;&#x4E0D;&#x4F1A;&#x5FFD;&#x7565;<code>null</code>&#xFF0C;&#x8FD4;&#x56DE;&#x8868;&#x7684;&#x300C;&#x884C;&#x6570;&#x300D;&#x3002;</li>
</ul>
<h2 id="123-md5&#x52A0;&#x5BC6;"><a name="123-md5&#x52A0;&#x5BC6;" class="anchor-navigation-ex-anchor" href="#123-md5&#x52A0;&#x5BC6;"><i class="fa fa-link" aria-hidden="true"></i></a>12.3. <code>MD5()</code>&#x52A0;&#x5BC6;</h2>
<p><strong>&#x4F5C;&#x7528;&#xFF1A;&#x589E;&#x5F3A;&#x7B97;&#x6CD5;&#x590D;&#x6742;&#x5EA6;&#xFF0C;&#x5E76;&#x4E14;&#x52A0;&#x5BC6;&#x4E0D;&#x53EF;&#x9006;&#x3002;</strong></p>
<ul>
<li><strong><code>MD5</code>&#x7684;&#x7834;&#x89E3;&#xFF1A;<code>MD5</code>&#x4E0D;&#x53EF;&#x9006;&#xFF0C;&#x53EA;&#x80FD;&#x5148;&#x6B63;&#x5411;&#x83B7;&#x53D6;&#x5230;&#x52A0;&#x5BC6;&#x5185;&#x5BB9;&#xFF0C;&#x7136;&#x540E;&#x4E0E;&#x8981;&#x7834;&#x89E3;&#x7684;&#x52A0;&#x5BC6;&#x5185;&#x5BB9;&#x8FDB;&#x884C;&#x5BF9;&#x6BD4;&#xFF0C;&#x5982;&#x679C;&#x4E00;&#x6837;&#x5C31;&#x7834;&#x89E3;&#x6210;&#x529F;&#x3002;</strong></li>
</ul>
<pre class="language-"><code class="lang-sql"><span class="token comment">-- &#x6DFB;&#x52A0;&#x52A0;&#x5BC6;&#x6570;&#x636E;</span>
<span class="token keyword">insert</span> <span class="token keyword">into</span> <span class="token punctuation">`</span>password<span class="token punctuation">`</span><span class="token punctuation">(</span><span class="token punctuation">`</span>name<span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>pwd<span class="token punctuation">`</span><span class="token punctuation">)</span> <span class="token keyword">values</span> 
<span class="token punctuation">(</span><span class="token string">&apos;&#x5C0F;&#x84DD;&apos;</span><span class="token punctuation">,</span>MD5<span class="token punctuation">(</span><span class="token string">&apos;12345&apos;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">(</span><span class="token string">&apos;&#x5C0F;&#x7EA2;&apos;</span><span class="token punctuation">,</span>MD5<span class="token punctuation">(</span><span class="token string">&apos;23456&apos;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">-- &#x67E5;&#x8BE2;&#x52A0;&#x5BC6;&#x6570;&#x636E;</span>
<span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> <span class="token punctuation">`</span>password<span class="token punctuation">`</span> 
<span class="token keyword">where</span> <span class="token punctuation">`</span>name<span class="token punctuation">`</span> <span class="token operator">=</span> <span class="token string">&apos;&#x5C0F;&#x84DD;&apos;</span> <span class="token operator">and</span> <span class="token punctuation">`</span>pwd<span class="token punctuation">`</span> <span class="token operator">=</span> MD5<span class="token punctuation">(</span><span class="token string">&apos;12345&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<h1 id="13-select&#x603B;&#x7ED3;"><a name="13-select&#x603B;&#x7ED3;" class="anchor-navigation-ex-anchor" href="#13-select&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a>13. <code>select</code>&#x603B;&#x7ED3;</h1>
<pre class="language-"><code class="lang-sql"><span class="token comment">-- &#x663E;&#x793A;&#x7ED3;&#x679C;</span>
<span class="token keyword">select</span> <span class="token punctuation">[</span><span class="token keyword">distinct</span><span class="token punctuation">]</span> <span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">1</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token number">2</span><span class="token punctuation">`</span><span class="token punctuation">,</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> 
<span class="token comment">-- &#x8868;</span>
<span class="token keyword">from</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token number">1</span><span class="token punctuation">`</span> <span class="token punctuation">[</span><span class="token keyword">as</span><span class="token punctuation">]</span> &#x522B;&#x540D;<span class="token number">1</span>
<span class="token comment">-- &#x8FDE;&#x63A5;&#x4E00;&#x4E2A;&#x8868;</span>
&#x65B9;&#x5F0F; <span class="token keyword">join</span> <span class="token punctuation">`</span>&#x8868;&#x540D;<span class="token number">2</span><span class="token punctuation">`</span> <span class="token punctuation">[</span><span class="token keyword">as</span><span class="token punctuation">]</span> &#x522B;&#x540D;<span class="token number">2</span>
<span class="token keyword">on</span> &#x522B;&#x540D;<span class="token number">1.</span><span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token punctuation">`</span> <span class="token operator">=</span> &#x522B;&#x540D;<span class="token number">2.</span><span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token punctuation">`</span>
<span class="token comment">-- &#x884C;&#x6570;&#x636E;&#x8FC7;&#x6EE4;</span>
<span class="token keyword">where</span> &#x8FC7;&#x6EE4;
<span class="token comment">-- &#x5206;&#x7EC4;</span>
<span class="token keyword">group</span> <span class="token keyword">by</span> <span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token punctuation">`</span>
<span class="token comment">-- &#x5206;&#x7EC4;&#x540E;&#xFF0C;&#x518D;&#x884C;&#x6570;&#x636E;&#x8FC7;&#x6EE4;</span>
<span class="token keyword">having</span> &#x7EC4;&#x8FC7;&#x6EE4;
<span class="token comment">-- &#x6392;&#x5E8F;</span>
<span class="token keyword">order</span> <span class="token keyword">by</span> <span class="token punctuation">`</span>&#x5B57;&#x6BB5;<span class="token punctuation">`</span> <span class="token keyword">asc</span><span class="token operator">/</span><span class="token keyword">desc</span>
<span class="token comment">-- &#x663E;&#x793A;&#x5185;&#x5BB9;</span>
<span class="token keyword">limit</span> &#x8D77;&#x59CB;&#x7D22;&#x5F15;<span class="token punctuation">,</span>&#x663E;&#x793A;&#x884C;&#x6570; <span class="token punctuation">;</span>
</code></pre>
<blockquote>
<p>[!warning|style:flat]
<span style="color:red;font-weight:bold"> &#x987A;&#x5E8F;&#x4E0D;&#x80FD;&#x4E71;&#xFF01;&#xFF01;&#xFF01; </span></p>
</blockquote>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="operatorDB_withNum.html" class="navigation navigation-prev " aria-label="Previous page: 三、数据库、表操作">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="transaction_withNum.html" class="navigation navigation-next " aria-label="Next page: 五、事务">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"四、数据操作","level":"3.1.4","depth":2,"next":{"title":"五、事务","level":"3.1.5","depth":2,"path":"MySQL/chapter/transaction_withNum.md","ref":"MySQL/chapter/transaction_withNum.md","articles":[]},"previous":{"title":"三、数据库、表操作","level":"3.1.3","depth":2,"path":"MySQL/chapter/operatorDB_withNum.md","ref":"MySQL/chapter/operatorDB_withNum.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","search-pro-fixed","expandable-chapters-small","ancre-navigation","hide-element","code","splitter","insert-logo-link-website","-sharing","sharing-plus","prism","-highlight","flexible-alerts","lightbox","pageview-count","auto-scroll-table","katex-pro","favicon-absolute","sectionx","terminull-light","livereload"],"styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"prism":{"css":["prismjs/themes/prism-tomorrow.css"],"lang":{"flow":"typescript"}},"livereload":{},"splitter":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"auto-scroll-table":{},"code":{"copyButtons":true},"terminull-light":{},"search-pro-fixed":{},"favicon-absolute":{"favicon":"image/ico.png","appleTouchIconPrecomposed152":"image/ico.png","appleTouchIconMore":{},"appleTouchIconPrecomposedMore":{}},"hide-element":{"elements":[".gitbook-link"]},"katex-pro":{},"fontsettings":{"theme":"white","family":"sans","size":2},"sectionx":{"tag":"b"},"lightbox":{"jquery":true,"sameUuid":false},"insert-logo-link-website":{"url":"image/logo.png","link":"https://space.bilibili.com/27206875","target":"_blank","style":"height: 230px"},"pageview-count":{},"ancre-navigation":{"showLevel":true,"associatedWithSummary":true,"mode":"float","printLog":false,"multipleH1":true,"float":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""},"pageTop":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""}},"expandable-chapters-small":{},"flexible-alerts":{"style":"callout","note":{"label":"Note","icon":"fa fa-info-circle","className":"info"},"tip":{"label":"Tip","icon":"fa fa-lightbulb-o","className":"tip"},"warning":{"label":"Warning","icon":"fa fa-exclamation-triangle","className":"warning"},"danger":{"label":"Attention","icon":"fa fa-ban","className":"danger"}},"sharing":{"qq":true,"all":["douban","facebook","google","instapaper","linkedin","twitter","weibo","messenger","qq","qzone","viber","whatsapp"],"douban":false,"facebook":false,"weibo":true,"whatsapp":false,"twitter":false,"pocket":false,"google":true,"qzone":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"海拉尔的三角","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"计算机笔记","links":{"sidebar":{"Github":"https://github.com/spite-triangle"}},"gitbook":"*"},"file":{"path":"MySQL/chapter/operatorData_withNum.md","mtime":"2021-09-14T15:43:13.580Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-09-14T15:43:23.052Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro-fixed/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro-fixed/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-insert-logo-link-website/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lightbox/js/lightbox.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-auto-scroll-table/plugin.js"></script>
        
    
        
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sectionx/sectionx.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-terminull-light/terminull.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

